1.
zlib을 쓸일이 있어서 공부하게 되었다.
zlib을 어느정도로 깊이 공부해야 하는지도 모르기 때문에 이제 시작~
2.
위키에서 찾아보니깐 'C로 작성된 데이터 압축 라이브러리' 라고 한다.
(http://ko.wikipedia.org/wiki/ZIP_(%ED%8C%8C%EC%9D%BC_%ED%8F%AC%EB%A7%B7))
한국 위키에선 별 다른 이야기가 없다. 미국 위키로 가보자.
3.
미국 위키는 Contents 부분만 한국보다 많다.
(https://en.wikipedia.org/wiki/Zlib)
근데 들어도 표면적인거라 그냥 넘겨들었다.
그래서 홈페이지에가서 직접 보기록 한다.
4.
사이트에서 처음 살펴볼 부분은 3부분인것 같다.
1. http://zlib.net/manual.html
2. http://zlib.net/zlib_how.html
3. http://zlib.net/zlib_tech.html
5.
manual을 살펴본다.
Introduction
The zlib compression library provides in-memory compression and decompression functions, including integrity checks of the uncompressed data. This version of the library supports only one compression method (deflation) but other algorithms will be added later and will have the same stream interface.
Compression can be done in a single step if the buffers are large enough (for example if an input file is mmap'ed), or can be done by repeated calls of the compression function. In the latter case, the application must provide more input and/or consume the output (providing more output space) before each call.
버퍼의 크기가 충분히 크면 1스텝, 그렇지 않으면 compression function을 repeated call해서 사용.
The compressed data format used by default by the in-memory functions is the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped around a deflate stream, which is itself documented in RFC 1951.
The library also supports reading and writing files in gzip (.gz) format with an interface similar to that of stdio using the functions that start with "gz". The gzip format is different from the zlib format. gzip is a gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
This library can optionally read and write gzip streams in memory as well.
gzip이 최적화되어서 좋다고 한다.
이 부분이 zlib과 gzip을 비교한 부분이다.
The zlib format was designed to be compact and fast for use in memory and on communications channels. The gzip format was designed for single- file compression on file systems, has a larger header than zlib to maintain directory information, and uses a different, slower check method than zlib.
The library does not install any signal handler. The decoder checks the consistency of the compressed data, so the library should never crash even in case of corrupted input.
6.
Stream Data Structures도 한번 보고 넘어가자.
typedef z_stream FAR *z_streamp;
typedef gz_header FAR *gz_headerp;
7.
Structures Usage
이게 중요한것 같다. 이건 굵은 글씨 할 필요가 없다. 전부 다 중요하다.
(must'들'만 봐도 알 수 있다.)
The application must update next_in and avail_in when avail_in has dropped to zero. It must update next_out and avail_out when avail_out has dropped to zero. The application must initialize zalloc, zfree and opaque before calling the init function. All other fields are set by the compression library and must not be updated by the application.
The opaque value provided by the application will be passed as the first parameter for calls of zalloc and zfree. This can be useful for custom memory management. The compression library attaches no meaning to the opaque value.
zalloc must return Z_NULL if there is not enough memory for the object. If zlib is used in a multi-threaded application, zalloc and zfree must be thread safe.
On 16-bit systems, the functions zalloc and zfree must be able to allocate exactly 65536 bytes, but will not be required to allocate more than this if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers returned by zallocfor objects of exactly 65536 bytes must have their offset normalized to zero. The default allocation function provided by this library ensures this (see zutil.c). To reduce memory requirements and avoid any allocation of 64K objects, at the expense of compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
The fields total_in and total_out can be used for statistics or progress reports. After compression, total_in holds the total size of the uncompressed data and may be saved for use in the decompressor (particularly if the decompressor wants to decompress everything in a single step).
8.
Constants를 보면 재미난다.
어떻게 보면 여기 정의된 것들이 모든 경우의 수니깐 여기를 이해하면 어느정도 윤곽은 잡히겠다.
Constants
Allowed flush values; see deflate() and inflate() below for details.
#define Z_NO_FLUSH 0 #define Z_PARTIAL_FLUSH 1 #define Z_SYNC_FLUSH 2 #define Z_FULL_FLUSH 3 #define Z_FINISH 4 #define Z_BLOCK 5 #define Z_TREES 6Return codes for the compression/decompression functions. Negative values are errors, positive values are used for special but normal events.
#define Z_OK 0 #define Z_STREAM_END 1 #define Z_NEED_DICT 2 #define Z_ERRNO (-1) #define Z_STREAM_ERROR (-2) #define Z_DATA_ERROR (-3) #define Z_MEM_ERROR (-4) #define Z_BUF_ERROR (-5) #define Z_VERSION_ERROR (-6)Compression levels.
#define Z_NO_COMPRESSION 0 #define Z_BEST_SPEED 1 #define Z_BEST_COMPRESSION 9 #define Z_DEFAULT_COMPRESSION (-1)Compression strategy — see deflateInit2() below for details.
#define Z_FILTERED 1 #define Z_HUFFMAN_ONLY 2 #define Z_RLE 3 #define Z_FIXED 4 #define Z_DEFAULT_STRATEGY 0Possible values of the data_type field (though see inflate()).
#define Z_BINARY 0 #define Z_TEXT 1 #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ #define Z_UNKNOWN 2The deflate compression method (the only one supported in this version).
#define Z_DEFLATED 8For initializing zalloc, zfree, opaque.
#define Z_NULL 0For compatibility with versions < 1.0.2.
#define zlib_version zlibVersion()
9.
나머지 Function에 대해서 설명도 있지만 이 부분은 너무 많고 그냥 필요할때 쓰는게 맞는것 같아서 전부 보진 않았다.
나중에 샘플 찾아서 공부할 때나 참고하면 좋을 듯.
이어서...
'소프트웨어' 카테고리의 다른 글
[펌] Zip 알고리즘 (0) | 2014.02.20 |
---|---|
[zlib] deflate algorithm에 대해서 (0) | 2014.02.18 |
[c++] pointer로 선언 후에 pointer를 그대로 넘겨서 pointer에 담아 사용하기 (0) | 2014.02.14 |
[c++] 스택에 저장된 곳을 다른 함수가 주소를 받아서 사용할 수 있을까? (0) | 2014.02.14 |
[c++] 상속이란 무엇인지는 아는데, 어떻게 쓰는 것인가? (0) | 2014.02.13 |