HOME > Zlib Advanced
Function Manual 
Zlib Advanced Function Manual
|  | 기본적으로 Basic Function만을 이용하면 압축과 복원을 할 수 있다. Zlib library에서 제공하는 그 외의 Function은 단순히 사용자 편의를 위한 것이다. 다만 Basic Function에서 제공하는 Deflate 압축 알고리즘과 GZIP을 혼동해서는 안 된다. GZIP은 Header, Compressed Data, 그리고 Trailer로 구성되어 있다. Deflate 알고리즘은 이 중 Compressed Data를 생성하기 위한 것이다. 주의!!! GZIP 파일 포맷으로 압축 및 복원하기 위해서는 Advanced Function의 도움을 받아야 한다. 특히 Advanced Function 중 deflateInit2와 inflateInit2함수에 주목하라. | 
| Function List | |
|  | 여기서는 필수적인 함수에 대해서만 간단히 설명하겠다. 필수적인 함수는 붉은 색으로 표시되어 있다. 나머지 함수는 Zlib home site에서 제공하는 매뉴얼에 링크되어 있다. | 
|  | int deflateInit2 (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy); | 
|  | int deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength); | 
|  | int deflateCopy (z_streamp dest, z_streamp source); | 
|  | int deflate Reset (z_streamp strm); | 
|  | int deflate Params (z_streamp strm, int level, int strategy); | 
|  | int inflateInit2 (z_streamp strm, int windowBits); | 
|  | int inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength); | 
|  | int inflateSync (z_streamp strm); | 
|  | int inflateReset (z_streamp strm); | 
|  |  | 
| Function Description | |||
|  | int deflateInit2
  (z_streamp strm, int level, int
  method, int windowBits, int memLevel,
  int strategy); | ||
|  |  | deflateInit2함수는 압축을 위한 초기화를 할 뿐, 압축 작업을 수행하지는 않는다. This is another version of deflateInit with more compression options. The fields next_in, zalloc, zfree and opaque must be initialized before by the caller. int level  int method è compression method. 무조건 Z_DEFLATED으로
  설정해야 한다.  è deflateInit는 MAX_WBITS(15)값을
  사용한다. GZIP 포맷으로 압축하기 위해서는 -15로 설정해야 한다. int memLevel è 압축을 위해 사용할 메모리의 양을 설정한다. è 1~9 사이의 값을 가지며, 값이 클수록 메모리 공간을 많이 확보한다. 물론 메모리를 많이 쓸수록 속도는 빨라진다. 기본적으로는 8을 사용한다. è See zconf.h for total
  memory usage as a function of windowBits and memLevel.  (Error
  Return) | |
|  |  |  | Z_OK if success. Z_MEM_ERROR if there was not enough memory. Z_STREAM_ERROR if a parameter is invalid (such as an invalid method). msg is
  set to null if there is no error message.  | 
|  |  | (예제) – 전체 
									소스 보기 | |
|  |  |  | int
  CGZipFile::Open( const char *_filename, const
  char *_mode ) {         int err;         gzipStream.zalloc
  = Z_NULL;         gzipStream.zfree
  = Z_NULL;         gzipStream.opaque
  = Z_NULL;         if ( _mode[0] == 'r' ){                fType
  = INFLATE;         }         else{                fType
  = DEFLATE;                                 err
  = deflateInit2( &gzipStream, compressLevel, Z_DEFLATED, -MAX_WBITS,                        DEF_MEM_LEVEL,
  Z_DEFAULT_STRATEGY );                if ( err != Z_OK )                        return 0;         }         fp
  = fopen( _filename, _mode );         return (int) fp; } | 
|  |  |  | |
|  | int inflateInit2
  (z_streamp
  strm, int windowBits); | ||
|  |  | This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller. è deflateInit는 MAX_WBITS(15)값을
  사용한다. GZIP 포맷을 복원하기 위해서는 -15로 설정해야 한다. è If a compressed stream with a larger window size is given as input, inflate() will return with the error code Z_DATA_ERROR instead of trying to allocate a larger window. (Error
  Return) | |
|  |  |  | Z_OK if success. Z_MEM_ERROR if there was not enough memory Z_STREAM_ERROR if a parameter is invalid (such as a negative memLevel). msg is set to null if there is no error message. | 
|  |  | (예제) – 전체 
									소스 보기 | |
|  |  |  | |
|  |  |  | |