zlib の使い方
zlib 訳  zlib.h  readme  faq  index



zlib1.2.2   <zlib.h>  訳

<以下の訳を読むにあたって>

     以下の訳は筆者が個人で訳したものです。
下記に間違い、誤訳等があったとしても当方は一切責任を負えません(英語苦手なので)。
正確な情報を求める方は必ず原文をお読みください。

zlib.h
英文
/*zlib.h -- 汎用圧縮ライブラリ「zlib 1.2.2」インターフェース
2004/11/3日。

著作(C) 1995-2004 ジーン・ループ ゲイリー と マーク アドラー

当該ソフトウェアは何の表示もなく暗黙の了解で「そのまま」提供されています。当該ソフトウェアの使用により発生したいかなる損害に対し著作者は一切責任 を 負いません。


当該ソフトウェアの使用については制約に従うかぎり、商用アプリケーションを含め、どんな目的でも自由に改変、再配布が許諾されます。


1.当該ソフトウェアのオリジナルを誤って伝えることを禁じます。あなたは自分でこのオリジナル・ソフトウェアを書いたといってはいけません。必須ではあ りませんが、製品内にあなたが当該ソフトウェアを使うなら製品文書のなかに謝辞文でも載せて頂ければ幸いです。
2.ソースを改変したものはそのように明示してください。オリジナル・ソフトウェアであるかのように誤って伝えてはいけません。
3.この注釈自体はソース配布時に改変、削除しても構いません。

ジーン・ループ ゲイリー   マーク アドラー
jloup@gzip.org          madler@alumni.caltech.edu


zlibライブラリで使われているデータ形式はRFCs
(Request for Comments)
・・・ (日本 RFC(JPNIC)) 1950-1952 で記述されています。
http://www.ietf.org/rfc/rfc1950.txt (zlibフォーマット)日本語訳,
rfc.1951.txt(圧縮フォーマット)日本語
,
rfc1952 (gzipフォーマット)日本語
*/
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.2, October 3rd, 2004

Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

Jean-loup Gailly     Mark Adler
jloup@gzip.org        madler@alumni.caltech.edu


The data format used by the zlib library is described by RFCs
(Request for Comments)
1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
(zlib format)
, rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/


#ifndef ZLIB_H
#define ZLIB_H

#include "zconf.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ZLIB_VERSION "1.2.2"
#define ZLIB_VERNUM 0x1220

#ifndef ZLIB_H
#define ZLIB_H

#include "zconf.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ZLIB_VERSION "1.2.2"
#define ZLIB_VERNUM 0x1220

/*
「zlib」圧縮ライブラリは非圧縮データの整合性のチェックを含め、メモリ内 圧縮・展開 関数を用意しています。このバージョンのライブラリ・サポートは圧縮命令(deflation)だけですが、他のアルゴリズムもあとで追加され、同じスト リーム・インターフェースになる予定です。

圧縮は、十分大きなバッファがあれば(例えば入力バッファがmmapされているとか)、一発で行うことができます。また圧縮関数を繰り返し複数回、呼ぶや り方でもできます。後者の場合、アプリケーションは関数を毎回呼び出す前に、
入力バッファを追加するか、出力バッファを使いきる(出力領域の追加を行う) か、またはその両方を行わなければなりません。

メモリ内 関数で、デフォルトで使われている圧縮データ形式は zlibフォーマットです。このフォーマットは
RFC 1950 に書かれている収縮ストリームを含んだ zlib ラッパであり、RFC 1951 に書かれているもの自身です。

ライブラリは、
stdio イ ンターフェースに似ている「gz」 文字列で始まる関数を使うファイルの読込・書込みもまたgzip(.gz)フォーマット内でサポートしています。gzip フォーマットは zip フォーマットと異なります。gzip は収縮ストリームを含み、RFC 1952 で文書化された gzip ラッパです。


当該ライブラリはメモリ内部でも同様に、任意に読込・書込みできます。

zlib フォーマットは、メモリ内部や通信経路上で使えるようにコンパクト・スピーディに設計されています。gzip フォーマットはファイルシステム上、単独ファイル圧縮で設計されており、ディレクトリ情報の維持のため zlib よりヘッダが大きくなり、さらに zlib よりチェック命令が遅い点が
zlib と異なります。

ライブラリはシグナル・ハンドラをインストールしません。入力が不正な場合でもライブラリがクラッシュしないように、デコーダは圧縮データの整合性を チェックします。
*/
/*
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.

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.

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.
*/


typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));

struct internal_state;

typedef struct z_stream_s {
Bytef *next_in; /* 次の入力バイト */
uInt avail_in; /* next_inの有効バイト数 */
uLong total_in; /* 読込のその時点での入力バイトの総バイト数 */

Bytef *next_out; /* 次の出力バイトの出力先 */
uInt avail_out; /* next_out の残りの空白 */
uLong total_out; /* 読込のその時点での出力バイトの総バイト数 */

char *msg; /* 最新エラーメッセージ, NULLならエラー無し */
struct internal_state FAR *state; /* アプリケーションからは見えません */

alloc_func zalloc; /* 内部のメモリ確保に使われます */
free_func zfree; /* 内部のメモリ解放に使われます */
voidpf opaque; /* zalloc と zfree に渡される プライベートデータ・オブジェクト */

int data_type; /* データタイプの最善予測: アスキーorバイナリ */
uLong adler; /* 非圧縮のadler32 値 */
uLong reserved; /* 将来使うための予約領域 */
} z_stream;

typedef z_stream FAR *z_streamp;


typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));

struct internal_state;

typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */

Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */

char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */

alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */

int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;

typedef z_stream FAR *z_streamp;

/*
アプリケーションは avail_in がゼロになっていたとき、next_in と avail_in を更新しなければなりません。avail_out がゼロになっていたときは、next_out と avail_out を更新しなければなりません。アプリケーションは初期関数を呼び出す前に zalloc、zfree と opque を初期化しなければなりません。他のすべての領域は圧縮ライブラリによってセットされるので、アプリケーションが更新してはいけません。

アプリケーションが用意する opque値は、zalloc、zfree の呼び出す関数に第一引数として渡します。これはメモリ管理のカスタム化に役立つことができます。圧縮ライブラリは opque値への意味付けを行いません。

zalloc はオブジェクト用のメモリが十分になかったときZ_NULLを返します。もし zlib がマルチスレッド・アプリケーションで使われてるなら
zalloc や zfree もスレッド・セーフになります。

16ビットシステムでは、関数 zalloc と zfree は65536バイトきっちりにメモリが確保できていなければなりませんが、MAXSEG_64K シンボルが定義されているなら(zconf.h を見てください)、それ以上のメモリ確保は必要ありません。警告:MSDOSで、正確に65536バイトのオブジェクトをzallocするときに返された ポインタはオフセットがゼロに正常化され「なければなりません」。当該ライブラリに用意されたデフォルトのメモリ確保関数はこれを保証します (zutil.c を見てください)。圧縮率を犠牲にすることで、メモリ必要量を減らすのと、64Kメモリをいくつも確保しないようにするには、-DMAX_WBITS= 14 でライブラリをコンパイルします(zconf.c を見てください)。

total_in と total_out 領域は統計やプログレス・レポートに使うことができます。圧縮後 total_in は非圧縮データのトータル・サイズを保持しており、展開時にまた使えるように保存しておいても良いでしょう(特に、もし展開関数が一回ですべて展開しよう とする時)。
*/

/*
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 zalloc for 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).
*/


/* 定数 */

#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 /* 削除予定, 代わりに Z_SYNC_FLUSH  を使います */
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
#define Z_BLOCK 5
/* flush 値のフラッシュ(全て出力する)許可; 詳細は deflate() と inflate() の下の方を見てください */

#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)
/* 圧縮/展開 関数の返り値コード。 マイナス * 値はエラーです。 正の値は特別な結果に使われますが正常な結果にも使われます. */

#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* 圧縮レベル */

#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_RLE 3
#define Z_DEFAULT_STRATEGY 0
/* 圧縮 戦略; 詳細は deflateInit2() の下の方を見てください */

#define Z_BINARY 0
#define Z_ASCII 1
#define Z_UNKNOWN 2
/* data_type 領域の使える値 (なんですが、inflate() を見てください) */

#define Z_DEFLATED 8
/* deflate 圧縮命令 (このバージョンでサポートされてるだけです) */

#define Z_NULL 0 /* zalloc, zfree, opaque 初期化 */

#define zlib_version zlibVersion()
/* バージョン < 1.0.2 の 互換用 */

/* constants */

#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
#define Z_BLOCK 5
/* Allowed flush values; see deflate() and inflate() below for details */

#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)
/* Return codes for the compression/decompression functions. Negative * values are errors, positive values are used for special but normal events. */

#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */

#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_RLE 3
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */

#define Z_BINARY 0
#define Z_ASCII 1
#define Z_UNKNOWN 2
/* Possible values of the data_type field (though see inflate()) */

#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */

#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */

#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */

/* 基本関数 */

ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* アプリケーションは整合チェックするために zlibVersion と  ZLIB_VERSION を比較できます。もし最初のキャラクタが異なっていたら, 実際に使われているライブラリ・コードは、アプリケーションで使われてる zlib.h ヘッダファイル と互換性がありません。この確認は deflateInit と inflateInit で自動的に行われます。
*/
/* basic functions */

ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check is automatically made by deflateInit and inflateInit.
*/

/*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));

圧縮用の内部ストリームを初期化します。 zalloc, zfreeと opaque は関数を呼び出す側が、関数を呼び出す前に初期化しなければなりません。 zalloc と zfree に Z_NULL がセットされたときは deflateInit がデフォルトのメモリ確保関数に更新します。

圧縮レベルは Z_DEFAULT_COMPRESSION かまたは 0 から 9の間でなければなりません… 1 が最も速く、9 は最も高圧縮です、0 は全データ非圧縮です(入力データが単純に1ブロックずつコピーされます)。 Z_DEFAULT_COMPRESSION は速度と圧縮率の間のデフォルト妥協値を求めます(現在は レベル6と等値です)。

deflateInit の返り値が Z_OK なら関数成功です。Z_MEM_ERROR ならメモリ不足です。Z_STREAM_ERROR なら圧縮レベルが有効値でないとき、 Z_VERSION_ERROR であれば zlib ライブラリ バージョン (zlib_version) が呼び出し側で想定されたバージョン(ZLIB_VERSION)と互換しないことを示します。msg に null がセットされていればエラーメッセージはありません。deflateInit はどんな圧縮も実行しません: 圧縮の実行は deflate()で行われます。
*/
/*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));

Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default allocation functions.

The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION requests a default compromise between speed and compression (currently equivalent to level 6).

deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level, Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible with the version assumed by the caller (ZLIB_VERSION). msg is set to null if there is no error message. deflateInit does not perform any compression: this will be done by deflate().
*/


ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/*
可能な限り大きいデータの
deflate 圧縮及び、 入力バッファが空になった時や出力バッファがいっぱいになったときの停止について、出力レイテンシー(なにも出力を取り出さずに入力を読み込むこと)を導入 してもいいです。無理やりフラッシュする場合を除いては。

セマンティクス詳細は下記のとおりです。deflate は下記動作のうち一つ又は両方実行します:

… 
next_in を先頭とした入力データを圧縮します。それに応じて avail_in と next_in を更新します。 もし入力を全て処理すことができなくても (出力バッファに十分な空きがなくて)、 next_in と avail_in を更新すれば、処理は次のdeflate() 関数の呼び出し時にこの点から再開します。

… next_out
を先頭としたデータ領域に出力を供給します。それに応じて next_out と avail_out を更新します。この動作は flush 引数が非ゼロなら強制的に実行されます。強 制フラッシュは少々圧縮率が低下するので、この引数は必要なときだけセットされるべきでしょう(対話系アプリケーションで)。たとえ flush がセットされてなくても、多少の出力ならいいです。

deflate() を呼び出す前に
アプリケーションは入力追加か出力消費の
両方またどちらかの少なくともひとつの可能なアクションを確実に行い、それにあわせて avail_in や avail_out を更新してください… 関数呼び出し前には avail_out は絶対ゼロになっていてはいけません。 アプリケーションは圧縮済みの出力を取り出したければ取 り出せます。例えば 出力バッファがいっぱいな時 (avail_out == 0)や、または各deflate() の呼出し後です。deflate 関数が avail_out をゼロ値にして Z_OK を返してきたときは、出力バッファに空きを作って再度関数を呼ばなければなりません。 なぜならまだ未処理のさらなる出力があるかもしれないからです。

flush 引数が Z_SYNC_FLUSH にセットされていたら、全ての未処理の出力が出力バッファにフラッシュされます。 そして展開関数がその時点で入手可能な全入力データを得られるように、出力は1バイト境界で整列されます(特に関数呼び出し前に用意された出力スペースが 十分なら関数呼出し後の avail_in はゼロになります)。圧縮アルゴリズムの性質的に
フラッシュは圧縮低下を招きますので必要なときだけ使うべきです。

flush に Z_FULL_FLUSH がセットされていたら Z_SYNC_FLUSHのように全出力がフラッシュされ圧縮状態がリセットされます。それ以前の圧縮されたデータが毀損していたり、ランダムアクセスを 要 求されたりしたときに、この点から展開が再スタートできるようにするためです。 Z_FULL_FLUSH を使うと本当にたまにですがひどい圧縮低下をおこします。

deflate 関数が avail_out == 0の状態で返ってきたら、flush パラメータは同値のまま、出力スペースを追加して(avail_out を更新する)、フラッシュが完了するまで (deflate 関数が avail_out を非ゼロの状態で返すまで)、この関数を何度も呼ばないと いけません。 Z_FULL_FLUSH や Z_SYNC_FLUSH の場合は、関数が返ってくる度に繰り返し avail_out == 0 でフラッシュ・マークが付けられないように avail_out が6より大きいことを確かめます。

flushパラメータが Z_FINISH がセットされていたら未処理の入力が処理されて、出力スペースが十分あれば未処理の出力がフラッシュされ deflate関数は Z_STREAM_END を返します… もし deflate が Z_OKで返ったらもう入力はありませんが、そうでなければ出力スペースを追加して(avail_out を更新する)、Z_STREAM_END で返るかまたはエラーがでるまで、この関数を Z_FINISHで繰り返し呼ばなければいけません。
deflate が Z_STREAM_END を返した 後は、ストリーム上で可能な命令は deflateReset か deflateEnd だけです。

圧縮がすべて一回で行われるようなら deflateInit の後すぐにZ_FINISH を使うことができます。この場合、avail_out は少なくとも deflateBound (下記参照)の返り値でなければなりません。 もし上記のように
deflate が Z_STREAM_END を返さなければ deflate を繰り返し呼ばなければなりません。

deflate() はその時点で読み込んだ全入力(total_in バイト).のadler32 チェックサムを strm->adler にセットします。

deflate() は入力データタイプ(Z_ASCII か Z_BINARY)をうまく予想することができれば data_type を更新するかもしれません。データがバイナリであると熟考されたとしても確信はありません。この領域は情報の目的のためだけにあり、 どんな方式の圧縮アルゴリズムにも影響しません。

deflate() が、Z_OK を返したら処理が進行したことを示します(追加された入力が処理された、または出力されたか)、Z_STREAM_END
が返ったら全ての入力が処理されて全出力が取出された (flush が Z_FINISH にセットされているときだけ)ことを示します、Z_STREAM_ERROR が返ったらストリーム状態が異常(例えば next_in や next_out が NULL のとき)です、Z_BUF_ERROR が返ったら処理が進められなかったとき(例えば avail_in や avail_out が zero だったとき)です。Z_BUF_ERROR はさほど重大なエラーではなくて、圧縮を継続するように入力を追加したり出力領域を追加したりすることでdeflate() を何度でも呼び出すことができま す。
*/
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/*
deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce some output latency (reading input without producing any output) except when forced to flush.

The detailed semantics are as follows. deflate performs one or both of the following actions:

- Compress more input starting at next_in and update next_in and avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in and avail_in are updated and processing will resume at this point for the next call of deflate().

- Provide more output starting at next_out and update next_out and avail_out accordingly. This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter should be set only when necessary (in interactive applications). Some output may be provided even if flush is not set.


Before the call of deflate(), the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating avail_in or avail_out accordingly; avail_out should never be zero before the call. The application can consume the compressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.


If the parameter flush is set to Z_SYNC_FLUSH, all pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far. (In particular avail_in is zero after the call if enough output space has been provided before the call.) Flushing may degrade compression for some compression algorithms and so it should be used only when necessary.

If flush is set to Z_FULL_FLUSH, all output is flushed as with Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using Z_FULL_FLUSH too often can seriously degrade the compression.

If deflate returns with avail_out == 0, this function must be called again
with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that avail_out is greater than six to avoid repeated flush markers due to avail_out == 0 on return.


If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was enough output space; if deflate returns with Z_OK, this function must be called again with Z_FINISH and more output space (updated avail_out) but no more input data, until it returns with Z_STREAM_END or an error. After deflate has returned Z_STREAM_END, the only possible operations on the stream are deflateReset or deflateEnd.

Z_FINISH can be used immediately after deflateInit if all the compression is to be done in a single step. In this case, avail_out must be at least the value returned by deflateBound (see below). If deflate does not return Z_STREAM_END, then it must be called again as described above.

deflate() sets strm->adler to the adler32 checksum of all input read so far (that is, total_in bytes).

deflate() may update data_type if it can make a good guess about the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered binary. This field is only for information purposes and does not affect the compression algorithm in any manner.

deflate() returns Z_OK if some progress has been made (more input processed or more output produced), Z_STREAM_END if all input has been consumed and all output has been produced (only when flush is set to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and deflate() can be called again with more input and more output space to continue compressing.
*/


ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
当該ストリームで
動的確保されたデー タ構造体のメモリが全て解放さ れます。この関数はどんな未処理の入力も出力も、フラッシュせずに破棄します。

deflateEnd が返す値は、 Z_OK なら成功、Z_STREAM_ERROR ならストリーム状態が異常、Z_DATA_ERROR なら早すぎるメモリ解放 (どっかの入力か出力で破棄された)ことを示します。エラーの場合、msg がセットされてるかもしれませんが、そのときは静的文字列へのポインタです (メモリ解放してはいけません)。
*/


ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output.

deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state was inconsistent, Z_DATA_ERROR if the stream was freed prematurely (some input or output was discarded). In the error case, msg may be set but then points to a static string (which must not be deallocated).
*/


/*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));

展開用内部ストリームの状態を初期化します。next_in、avail_in、zalloc、zfree、 opaque の領域は呼び出し側が初期化しなければなりません。next_in が Z_NULL でなく、avail_in が十分大きい (正確な値は圧縮命令で決まります)なら、それに応じてinflateInit は zlib ヘッダから圧縮命令を決定し、全てのデータ構造体のメモリを確保します… そうでなければメモリ確保は最初の inflate 関数呼び出しに従います。zalloc と zfree にZ_NULL がセットされていたら inflateInit はそれらをデフォルトメモリ確保関数に更新します。

inflateInit が返す値は、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_VERSION_ERROR なら呼び出し側の想定した zlib ライブラリバージョンと互換性ないことを示します。 msg に null がセットされていたらエラーメッセージはありません。inflateInit は 与えられたzlib ヘッダの読込(inflate()で実行されます)は別として、どんな展開も実行はしません(next_in と avail_in は変更されるかもしれませんが、next_out と avail_out は変更されません)。
*/
/*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));

Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by the caller. If next_in is not Z_NULL and avail_in is large enough (the exact value depends on the compression method), inflateInit determines the compression method from the zlib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first call of inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to use default allocation functions.

inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the version assumed by the caller. msg is set to null if there is no error message. inflateInit does not perform any decompression apart from reading the zlib header if present: this will be done by inflate(). (So next_in and avail_in may be modified, but next_out and avail_out are unchanged.)
*/

ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/*
inflate 関数はできるだけ多くのデータを展開していき、入力バッファ空になるか出力バッファがいっぱいになったら停止します。無理にフラッシュする場合を除けば、 出力レイテンシー(何も出力を取り出さずに入力を読み込むこと)
があってもいいです

セマンティクス詳細は下記のとおりです。 inflate は下記アクションのうちひとつまたは両方実行します:

- next_in を先頭とした入力データを展開していき、それに応じて next_in と avail_in を更新します。もし入力が
全て処 理されることができなくても (出力バッファに十分な空きがない理由から)、next_in と avail_in は更新され、処理は次のinflate() 関数の呼び出し時にこの点から再開します。

- next_out
を先頭としたデータ領域に出力を書き込み、それに応じて next_out と avail_out を更新します。inflate() は入力データが無くなるか、出力バッファにスペースがなくなるまで、できるだけ出力を書き込みます(flush 引数については下記参照)。

inflate() を呼ぶ前に
アプリケーションは、 入力の追加と出力領域消費の両方またはどちらか少なくとも可能なアクションのひとつを確実に行い、 そしてそれにあわせて next_* と avail_* の値を更新してください。アプリケーションは展開済み出力を取り出したければ取り出せます。例えば 出力バッファがいっぱい(avail_out == 0)のときや、inflate()を各呼び出し後などです。inflate 関数が Z_OK を返し、avail_outがゼロなら、未処理の出力があるかもしれないため、出力バッファに空きを作り再度 inflate 関数を呼ばなければなりません。

inflate() の flush 引数は Z_NO_FLUSH、Z_SYNC_FLUSH、 Z_FINISH か Z_BLOCK になります。Z_SYNC_FLUSH は inflate() に出力バッファへ
可能な限 りフラッシュすることを要求します。Z_BLOCK は inflate() に次の deflate ブロック境界で停止するよう要求します。これ は zlib や gzip フォーマットをデコードするとき、ヘッダの後の最初のブロックの前の位置から直ちに返ります。未処理の inflate を実行するとき、inflate() は最初のブロックから処理し、最後のブロックを得るか、データがなくなったとき返ります。

Z_BLOCK オプションは deflate ストリームの結合や付加に役立ちます。 inflate() が返るとき set strm->data_type にstrm->next_in の最後のバイトの使われてないビット番号をセットします。+64 なら inflate() が今 deflate ストリームで最後のブロックをデコードしていることを示します。また +128 なら end-of-block コードをひとつデコードしたあとか、deflate ストリームのまさに最初のバイトの前までヘッダを完全にデコードしたときは、inflate()はすぐ返ります。 end-of-block は strm->next_out に書き込まれたブロックから展開データの全部を指し示しているわけではありません。
data_type の第7ビットがセットされてるときを除いて、使われてないビットの番号は一般に7より大きいで す。その場合、使われてないビット番号は8より小さいです


inflate() は通常 Z_STREAM_END かエラーが返るまで呼ばれます。しかしながら全ての展開を一発(inflate呼び出しを
一 回で済ませる)で完了できるなら flush 引数は Z_FINISHにセットされるべきです。この場合、未処理の入力が処理され、未処理の出力はフラッシュされます… avail_out は展開データを保持できるだけの大きさが必要です(展開データのサイズはこの目的のために呼び出し側が保存しといてもいいです)。このスト リーム上ので次の命令は展開データを解放する inflateEnd でなければなりません。Z_FINISH の使用は決して必要というわけではありませんが、高速に進行する一発 inflate() 関数の情報取得に使えます。


この実行では inflate() は、常にめいっぱいに出力バッファに出力しようとし、
常に最初の関数呼び出しでより速い進行を行おうとします。この実行で Z_BLOCK を使い早く返るようにした時や、下記のようなときflush 引数の影響結果だけは、 inflate() の返り値上にあります。


プリセット・ディクショナリがこの関数 (下記の inflateSetDictionary を見てください)呼び出し後必要とされるようなら、inflate 関数は圧縮関数側に選択されたディクショナリの adler32 チェックサム を
strm->adler にセットし、 Z_NEED_DICT を返します… さもなくば その時点で取り出された全出力(total_out バイト)を adler32 チェックサムをstrm->adler にセットし、Z_OK、Z_STREAM_END か下記のエラーコードを返します。ストリームの終わりに、inflate() は圧縮関数に保存された値と adler32 チェックサムが等しいか計算して確認し、チェックサムが正しいなら Z_STREAM_END を返します。

inflate() は zlib-wrapped か gzip-wrapped のどちらか収縮データを展開し、チェックします。ヘッダタイプは自動的に検知されます。gzip ヘッダ内の
情報は何も保持され ないので、アプリケーションは未処理の inflate を処理するための代わりの情報を必要とします。下記の inflateInit2() を見てください。または inflateBack() と gzip ヘッダとトレイラの自身の処理を実行します。

inflate() が 返り値が Z_OK なら処理が進んだこと(入力が処理されたか、出力が書き込まれたか)
を示します、Z_STREAM_END は圧縮データが終点に達し全ての展開データが出力されたことを示します、Z_NEED_DICTはプリセット・ディクショナリがこのポイントで必要とされ ていることを示します。 Z_DATA_ERROR なら入力データが壊れています(入力ストリームフォーマットに適合しないか不正チェック値です)、Z_STREAM_ERROR ならストリーム構造体が異常です (例えば next_in や next_out が NULLだったり)、Z_MEM_ERROR なら十分なメモリがありません、Z_BUF_ERROR なら Z_FINISH が使われてる時で処理が進められなかったか出力バッファに十分な空きがありません。ですが注意してほしいのは Z_BUF_ERROR はさほど重大なエラーではなく 展開を継続するために入力や出力スペースの追加を行うことで再度inflate() を呼ぶことができます。Z_DATA_ERROR が返ったときで且つ部分的リカバリのデータが要求されてるとき、アプリケーションは inflateSync() 関数で正常圧縮ブロックを探すことができます。
*/

ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/*
inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce some output latency (reading input without producing any output) except when forced to flush.

The detailed semantics are as follows. inflate performs one or both of the following actions:

- Decompress more input starting at next_in and update next_in and avail_in accordingly. If not all input can be processed (because there is not enough room in the output buffer), next_in is updated and processing will resume at this point for the next call of inflate().

- Provide more output starting at next_out and update next_out and avail_out accordingly. inflate() provides as much output as possible, until there is no more input data or no more space in the output buffer (see below about the flush parameter).

Before the call of inflate(), the application should ensure that at least one of the actions is possible, by providing more input and/or consuming more output, and updating the next_* and avail_* values accordingly. The application can consume the uncompressed output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of inflate(). If inflate returns Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending.

The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much output as possible to the output buffer. Z_BLOCK requests that inflate() stop if and when it get to the next deflate block boundary. When decoding the zlib or gzip format, this will cause inflate() to return immediately after the header and before the first block. When doing a raw inflate, inflate() will go ahead and process the first block, and will return when it gets to the end of that block, or when it runs out of data.

The Z_BLOCK option assists in appending to or combining deflate streams. Also to assist in this, on return inflate() will set strm->data_type to the number of unused bits in the last byte taken from strm->next_in, plus 64 if inflate() is currently decoding the last block in the deflate stream, plus 128 if inflate() returned immediately after decoding an end-of-block code or decoding the complete header up to just before the first byte of the deflate stream. The end-of-block will not be indicated until all of the uncompressed data from that block has been written to strm->next_out. The number of unused bits may in general be greater than seven, except when bit 7 of data_type is set, in which case the number of unused bits will be less than eight.

inflate() should normally be called until it returns Z_STREAM_END or an error. However if all decompression is to be performed in a single step (a single call of inflate), the parameter flush should be set to Z_FINISH. In this case all pending input is processed and all pending output is flushed; avail_out must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been saved by the compressor for this purpose.) The next operation on this stream must be inflateEnd to deallocate the decompression state. The use of Z_FINISH is never required, but can be used to inform inflate that a faster approach may be used for the single inflate() call.

In this implementation, inflate() always flushes as much output as possible to the output buffer, and always uses the faster approach on the first call. So the only effect of the flush parameter in this implementation is on the return value of inflate(), as noted below, or when it returns early because Z_BLOCK is used.

If a preset dictionary is needed after this call (see inflateSetDictionary below), inflate sets strm->adler to the adler32 checksum of the dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise it sets strm->adler to the adler32 checksum of all output produced so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described below. At the end of the stream, inflate() checks that its computed adler32 checksum is equal to that saved by the compressor and returns Z_STREAM_END only if the checksum is correct.

inflate() will decompress and check either zlib-wrapped or gzip-wrapped deflate data. The header type is detected automatically. Any information contained in the gzip header is not retained, so applications that need that information should instead use raw inflate, see inflateInit2() below, or inflateBack() and perform their own processing of the gzip header and trailer.

inflate() returns Z_OK if some progress has been made (more input processed or more output produced), Z_STREAM_END if the end of the compressed data has been reached and all uncompressed output has been produced, Z_NEED_DICT if a preset dictionary is needed at this point, Z_DATA_ERROR if the input data was corrupted (input stream not conforming to the zlib format or incorrect check value), Z_STREAM_ERROR if the stream structure was inconsistent (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no progress is possible or if there was not enough room in the output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and inflate() can be called again with more input and more output space to continue decompressing. If Z_DATA_ERROR is returned, the application may then call inflateSync() to look for a good compression block if a partial recovery of the data is desired.
*/


ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/*
動的確保されたデー タ構造体メモリ全て解放されます。この関数は、未処理の入力を破棄し、 未処理の出力もフラッシュされません。

inflateEnd の返り値は Z_OK なら成功、Z_STREAM_ERROR ならストリーム状態が異常です。エラーの場合、msg がセットされてるかもしれませんがその時は静的文字列へのポインタです(メモリ解放してはいけません)。
*/
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output.

inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state was inconsistent. In the error case, msg may be set but then points to a static string (which must not be deallocated).
*/

/* 応用 関数 */

/*
下記関数を必要とするのは特殊なアプリケーションだけです。
*/
/* Advanced functions */

/*
The following functions are needed only in some special applications.
*/

/*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy));

これは
deflateInit もうひとつのバージョンで、さらに圧縮オプションのついてます。next_in、 zalloc、zfree、opaque 領域は関数に呼ばれる前に初期化されなければなりません。

method 引数は 圧縮命令です。 このライブラリ・バージョンではそれは Z_DEFLATED でなければなりません。

windowBits引数はウィンドウサイズ(履歴バッファ・サイズ)の2を底とした対数です。このライブラリバージョンでは 8〜15の間です。この引数が大きい数値ならメモリを使用消費することで圧縮が向上します。 deflateInit の代わりに使った時など標準値は 15 です。

windowBits は未処理の deflate 用に -8 〜 -15 になります。この場合、 -windowBits でウィンドウ・サイズを決定します。zlib ヘッダやトレイラがなくて未解決の収縮データを生じたとき
deflate() は、adler32 チェック値を計算します。


windowBits はオプションの gzip エンコード用に15より大きくなることもあります。zlib ラッパの代わりに圧縮データを囲んだシンプルな gzip ヘッダとトレイラを書き込んだとき windowBits に16を加えます。gzip ヘッダにはファイル名も、拡張データも、コメントも、更新時間(ゼロになってます)も、 ヘッダcrcも無く、オペレーティングシステムは255 (unknown)にセットされます。 gzip ストリームが書き込まれているなら、strm->adler は adler32 の代わりに crc32 になります。

memLevel 引数は内部の圧縮状態用にどれくらいメモリを確保すればいいのか詳述します。memLevel=1 は最小メモリでの使用ですが遅く、圧縮率も低くなります; memLevel=9 は最大メモリでの使用で最適な速度になります。デフォルト値は8です。windowBits と memLevel の関数などのトータルメモリ使用については zconf.h を見てください。


strategy 引数は本当の圧縮アルゴリズムで使われてます。Z_DEFAULT_STRATEGY 値なら通常データを使います。Z_FILTERED はフィルタ(事前想定)により取り出されたデータです。Z_HUFFMAN_ONLY はHuffman 法だけによるエンコードです(文字列マッチじゃないです)。 フィルタされたデータはいくらか無作為分配され、大部分が小さな値となります。この場合圧縮アルゴリズムはより優れた圧縮へと変えられます。 Z_FILTERED の効果はより多いハフマン・コードとより少ない文字列マッチに無理やりします… Z_DEFAULT と Z_HUFFMAN_ONLY の中間くらいです。Z_RLE はZ_HUFFMAN_ONLY と同じくらい速く設計されていますが、 PNG 画像データのより良い圧縮を与えてくれます。strategy パラメータは圧縮された出力が正当でない場合をのぞいて、たとえ適切にセットされてなくても、圧縮率に作用します。

deflateInit2 の返り値が、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_STREAM_ERROR ならパラメータ無効(例えば無効命令とか)です。 msg が null ならエラーメッセージはありません。deflateInit2 は圧縮を実行しません… deflate()によって行われます。
*/
/*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy));

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.

The method parameter is the compression method. It must be Z_DEFLATED in this version of the library.

The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. Larger values of this parameter result in better compression at the expense of memory usage. The default value is 15 if deflateInit is used instead.

windowBits can also be -8..-15 for raw deflate. In this case, -windowBits determines the window size. deflate() will then generate raw deflate data with no zlib header or trailer, and will not compute an adler32 check value.

windowBits can also be greater than 15 for optional gzip encoding. Add 16 to windowBits to write a simple gzip header and trailer around the compressed data instead of a zlib wrapper. The gzip header will have no file name, no extra data, no comment, no modification time (set to zero), no header crc, and the operating system will be set to 255 (unknown). If a gzip stream is being written, strm->adler is a crc32 instead of an adler32.

The memLevel parameter specifies how much memory should be allocated for the internal compression state. memLevel=1 uses minimum memory but is slow and reduces compression ratio; memLevel=9 uses maximum memory for optimal speed. The default value is 8. See zconf.h for total memory usage as a function of windowBits and memLevel.

The strategy parameter is used to tune the compression algorithm. Use the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no string match), or Z_RLE to limit match distances to one (run-length encoding). Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress them better. The effect of Z_FILTERED is to force more Huffman coding and less string matching; it is somewhat intermediate between Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately.

deflateInit2 returns 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. deflateInit2 does not perform any compression: this will be done by deflate().
*/

ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, const Bytef *dictionary, uInt dictLength));
/*
圧縮された出力データからは全く消費せずに、与えられた連続バイトデータから圧縮ディクショナリを初期化します。
この関数はdeflateInit や deflateInit2 や deflateReset関数が呼ばれたらどの圧縮関数よりも前に、ただちに呼ばれなければなりません。圧縮関数と展開関数は正確に同じディク ショナリが使われなければなりません(inflateSetDictionaryを見て下さい)。

ディクショナリはこれから圧縮されるデータで且つこれから出てきそうな文字列(連続バイト)、最も一般的に使われてる文字列よりむしろディクショナリの終 わり に向かって置かれている文字列、で構成されます。圧縮されるデータが短く、良い精度で予想できるとき、ディクショナリの利用がもっとも役立ちます… デフォルトの空のディクショナリより、良い圧縮ができるデータのとき。

ディクショナリの一部は結果として破棄されることもあり、deflateInit や deflateInit2に選択された圧縮データ構造体サイズに左右されます。例えばdeflateInit や deflateInit2にあるウィンドウサイズより大きいときなど。従って最も役立ちそうな文字列はディクショナリの前でなく終わりに置かれます。

この関数が返るとき、strm->adler はディクショナリの adler32 値にセットされます… 圧縮関数に使われたディクショナリを決定するためのこの値を、展開関数があとで使うはずなので(adler32 値は、たとえ圧縮関数に実際に使われたのがディクショナリの部分集合だけでも全ディクショナリを適用します)。処理したことのない deflate が要求されたら、adler32 値は計算されず、strm->adler もセットされません。

deflateSetDictionary の返り値は、Z_OK なら成功、またZ_STREAM_ERROR ならパラメータ無効(ディクショナリがNULL とか) かストリーム状態が異常(例えば deflate が既にこのストリームのために呼ばれたとか、圧縮命令がbsortであるとか)
です。 deflateSetDictionary はどんな圧縮も実行しません…圧縮は deflate() によって実行されます。
*/


ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, const Bytef *dictionary, uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence without producing any compressed output. This function must be called immediately after deflateInit, deflateInit2 or deflateReset, before any call of deflate. The compressor and decompressor must use exactly the same dictionary (see inflateSetDictionary).

The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary.

Depending on the size of the compression data structures selected by deflateInit or deflateInit2, a part of the dictionary may in effect be discarded, for example if the dictionary is larger than the window size in deflate or deflate2. Thus the strings most likely to be useful should be put at the end of the dictionary, not at the front.

Upon return of this function, strm->adler is set to the adler32 value of the dictionary; the decompressor may later use this value to determine which dictionary has been used by the compressor. (The adler32 value applies to the whole dictionary even if only a subset of the dictionary is actually used by the compressor.) If a raw deflate was requested, then the adler32 value is not computed and strm->adler is not set.

deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid (such as NULL dictionary) or the stream state is inconsistent (for example if deflate has already been called for this stream or if the compression method is bsort). deflateSetDictionary does not perform any compression: this will be done by deflate().
*/


ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, z_streamp source));
/*
コピー元ストリームをコピー先ストリームにコピーします。


いくつか圧縮方式を試すときこの関数は役立ちます。 例えば、フィルタ付入力データの前処理の方法が数種類あるときです。ストリームはdeflateEnd が呼ばれ解放されるときに破棄されます。deflateCopy の注意として、本当に大きくなるような内部の圧縮状態が重複するのでこの方策は遅いうえに大量のメモリを消費します。

deflateCopy の返り値は、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_STREAM_ERROR ならコピー元ストリーム状態が異常( zalloc が NULL だったり)
です。msg はコピー元とコピー先に変更がないことが書き残されてます。
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.

This function can be useful when several compression strategies will be tried, for example when there are several ways of pre-processing the input data with a filter. The streams that will be discarded should then be freed by calling deflateEnd. Note that deflateCopy duplicates the internal compression state which can be quite large, so this strategy is slow and can consume lots of memory.

deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc being NULL). msg is left unchanged in both source and destination.
*/

ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
この関数は deflateInit の後で呼ばれる deflateEnd と同等ですが、内部圧縮の
メモリ解 放も、メモリ再確保もしません。このストリームは同じ圧縮レベルと deflateInit2 にセットされているであろう他の属性を保持します。

deflateReset の返り値は、Z_OK なら成功、また Z_STREAM_ERROR なら元のストリーム状態が異常(zalloc や state が NULLとか)
です。
*/


ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate all the internal compression state. The stream will keep the same compression level and any other attributes that may have been set by deflateInit2.

deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being NULL).
*/


ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level,
int strategy));
/*
圧縮レベルと圧縮方法が動的に更新されます。圧縮レベルと圧縮方法の解釈は deflateInit2 内のもの
に似ています。これは入力データの直接コピーと圧縮を切り替えて使うか、それか異なる圧縮方 法を使う異なる種類の入力デー タに切り替えて使うかします。 圧縮レ ベルが変えられても、その時点で有効な入力は変えられる前のレベルで圧縮されます(そしてフラッシュされます)… 新レベルは次の deflate() 呼び出しでだけ効果があります。

deflateParams を呼び出す前に、ストリームをdeflate()を呼び出すためにセットしなければなりません。そして現在の入力から圧縮され、フラッシュされま す。とりわけ、strm->avail_out は非ゼロでなければなりません。

deflateParams の返り値は、Z_OK なら成功、Z_STREAM_ERROR なら元のストリーム状態が異常か、パラメータが無効です。Z_BUF_ERROR なら strm->avail_out がゼロです。
*/

ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level,
int strategy));
/*
Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2. This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level (and may be flushed); the new level will take effect only at the next call of deflate().

Before the call of deflateParams, the stream state must be set as for a call of deflate(), since the currently available input may have to be compressed and flushed. In particular, strm->avail_out must be non-zero.

deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if strm->avail_out was zero.
*/

ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
uLong sourceLen));
/*
deflateBound() は sourceLen バイトの収縮後の圧縮サイズ上の上限値を返します。 deflateInit() や deflateInit2() のあとで呼ばなければなりません。deflate()関数が呼ばれる前に、一括圧縮用の出力バッファのメモリ確保に使われます。
*/

ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
uLong sourceLen));
/*
deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or deflateInit2(). This would be used to allocate an output buffer for deflation in a single pass, and so would be called before deflate().
*/

ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int bits,
int value));
/*
deflatePrime() は圧縮出力ストリ−ムにビットを挿入します。目的は、この関数が前の deflate 出力に残余ビットを伴ったときの deflate 出力の始動時に使うことです。このように、この関数は未処理の deflate のために使うことだけができ、一番最初の deflate()の前で且つ、deflateInit2() や deflateReset()の後に呼ばれなければなりません。
ビットは16以下でなければならず、値の最小有意ビットの多くが出力に挿入されます。

deflatePrime の返り値は、Z_OK なら成功、また Z_STREAM_ERROR なら元のストリーム状態が異常です。
*/


ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int bits,
int value));
/*
deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits leftover from a previous deflate stream when appending to it. As such, this function can only be used for raw deflate, and must be used before the first deflate() call after a deflateInit2() or deflateReset(). bits must be less than or equal to 16, and that many of the least significant bits of value will be inserted in the output.

deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent.
*/


/*
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits));

これは拡張引数の付いた inflateInit のもうひとつのバージョンです。 next_in、avail_in、zalloc、zfre、opaque は関数呼び出し側が前もって初期化しておかなければなりません。

windowBits パラメータは最大ウィンドウサイズ(履歴バッファ・サイズ)の2を底とする対数です。このライブラリのバージョンではそれは8〜15の間になります。 inflateInit 関数の代替として使うのなら、デフォルト値の15です。windowBits は、圧縮中に deflateInit2() が使う windowBits の値以上である必要があります。また deflateInit2() を使わないときは15でなければなりません。ウィンドウサイズがもう
十分大きい圧縮ストリームに入力等が渡されたら、inflate () 関数はまたさらに大きなウィンドウ・メモリ確保をしようとはせずに Z_DATA_ERROR エラーコードを返します。

windowBits は未処理 inflate 用に -8 〜 -15 にもなり得ります。この場合、-windowBits がウィンドウサイズになります。inflate() 関数が未処理の圧縮データを処理しようとするとき、zlib ヘッダや gzip ヘッダも探さないし、チェック値もつくらず、ストリームの終わりにある比較用チェック値も全く探しません。これは zip のような圧縮データフォーマットを使用する他のフォーマットの使用のためです。それらのフォーマットは自身のチェック値を供給します。 カスタム・フォーマットが圧縮データ用に未圧縮フォーマットを使って開発されたのなら、 adler32 や crc32 のようなzlib、gzip、zip 内で処理されたそのままの未圧縮データを用いたチェック値を推奨します。ほとんどのアプリケーションは、zlib フォーマットをそのまま使うべきでしょう。deflateInit2() を使う上では windowBits の大きさが適用されることに注意してください。

windowBits はオプションの gzip デコード用に15より大きな値にもなり得ます。 windowBits に32を加えると、ヘッダ自動探知付きの zlib と gzip デコードが可能になります。また16を加えれば gzip フォーマットだけデコードします( zlib フォーマットは Z_DATA_ERROR を返します。gzip フォーマットがデコードされているとき、strm->adler は adler32 の代わりに crc32 になります)。

inflateInit2 の返り値は、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_STREAM_ERROR ならパラメータが無効(memLevel が負数とか)
です。 msg が null ならエラーメッセージはありません。zlib ヘッダが渡されたときのその読込を別にすれば、inflateInit2 はどんな圧縮も実行しません… 圧縮はinflate() が実行します(next_in と avail_in が変更されるかもしれませんが、next_out と avail_out は変更されません)。
*/


/*
ZEXTERN int ZEXPORT inflateInit2 OF((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.

The windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. The default value is 15 if inflateInit is used instead. windowBits must be greater than or equal to the windowBits value provided to deflateInit2() while compressing, or it must be equal to 15 if deflateInit2() was not used. 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.

windowBits can also be -8..-15 for raw inflate. In this case, -windowBits determines the window size. inflate() will then process raw deflate data, not looking for a zlib or gzip header, not generating a check value, and not looking for any check values for comparison at the end of the stream. This is for use with other formats that use the deflate compressed data format such as zip. Those formats provide their own check values. If a custom format is developed using the raw deflate format for compressed data, it is recommended that a check value such as an adler32 or a crc32 be applied to the uncompressed data as is done in the zlib, gzip, and zip formats. For most applications, the zlib format should be used as is. Note that comments above on the use in deflateInit2() applies to the magnitude of windowBits.

windowBits can also be greater than 15 for optional gzip decoding. Add 32 to windowBits to enable zlib and gzip decoding with automatic header detection, or add 16 to decode only the gzip format (the zlib format will return a Z_DATA_ERROR. If a gzip stream is being decoded, strm->adler is a crc32 instead of an adler32.

inflateInit2 returns 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. inflateInit2 does not perform any decompression apart from reading the zlib header if present: this will be done by inflate(). (So next_in and avail_in may be modified, but next_out and avail_out are unchanged.)
*/


ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
与えられた 非圧縮の連続バイトから、圧縮ディクショナリを初期化します。inflate関数を呼んでZ_NEED_DICTが返ったとき、この関数はその直後にすぐに呼ばれなければなりません。 圧縮関数が選択したディクショナリは inflate関数が返した adler32 値で決められます。圧縮関数と展開関数はまったく同じ関数を使わなければなりません(deflateSetDictionaryを見て下さ い)。

inflateSetDictionary の返り値は、Z_OK なら成功、Z_STREAM_ERROR ならパラメータが無効(ディクショナリが NULL とか) か、またはストリームが異常です。Z_DATA_ERROR なら与えられたディクショナリが予想されたものと合致しないことを示します(adler32 値が不正です)。inflateSetDictionary はどんな展開も実行しません…
展開は後で呼ぶ inflate() 関数が実行します。
*/


ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen by the compressor can be determined from the adler32 value returned by this call of inflate. The compressor and decompressor must use exactly the same dictionary (see deflateSetDictionary).

inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a parameter is invalid (such as NULL dictionary) or the stream state is inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the expected one (incorrect adler32 value). inflateSetDictionary does not perform any decompression: this will be done by subsequent calls of inflate().
*/


ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
無効な圧縮データを、探知可能な
全てフラッシュするポイント(上述の Z_FULL_FLUSH 引数での deflate を見てください)までスキップするか、入力が全て有効なところまでスキップします。出力はありません。

inflateSync は全てフラッシュする
ポイントが探知されると Z_OK を返します。Z_BUF_ERROR なら入力がありません。Z_DATA_ERROR なら探知された点でフラッシュがありません。また、Z_STREAM_ERROR ならストリーム構造体が異常です。成功した場合、アプリケーションは圧縮したデータが見つかった場所を指し示す現在の total_in の流動値を保存できます。エラーの場合、アプリケーションはその都度入力を追加しながら、成 功する入力データが終わるまで再三 inflateSync を呼ぶことができます。
*/


ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until a full flush point (see above the description of deflate with Z_FULL_FLUSH) can be found, or until all available input is skipped. No output is provided.

inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the success case, the application may save the current current value of total_in which indicates where valid compressed data was found. In the error case, the application may repeatedly call inflateSync, providing more input each time, until success or end of the input data.
*/


ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
z_streamp source));
/*
コピー元ストリームをコピー先ストリームへコピーします。


この関数は大きなストリームにランダムアクセスするとき便利です。ストリームの各第一関門の inflate 状態を
定期的に記録することが でき、ストリームにランダムアクセスするときそれらの記録点から inflate を再開することが可能になります。

inflateCopy の返り値は、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_STREAM_ERROR なら元のストリーム状態が異常(zalloc が NULL になってるとか)
です。 msg はコピー元とコピー先両方とも変更ないままになります。
*/


ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.

This function can be useful when randomly accessing a large stream. The first pass through the stream can periodically record the inflate state, allowing restarting inflate at those points when randomly accessing the stream.

inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc being NULL). msg is left unchanged in both source and destination.
*/


ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
この関数は inflateInit の後で呼ばれる inflateEnd と同等ですが、
展開内部の状態メモリ解放も再確保も全くしません。ストリームは inflateInit2 がセットしたであろう属性を保持します。

inflateReset の返り値は、Z_OK なら成功、また Z_STREAM_ERROR なら元のストリーム状態が異常(zalloc や state が NULL とか)
です
*/


ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate all the internal decompression state. The stream will keep attributes that may have been set by inflateInit2.

inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being NULL).
*/


/*
ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, unsigned char FAR *window));

inflateBack()関数に使う展開用内部ストリームを初期化します。strm の中の領域 zalloc、zfree、opaque は関数を呼ぶ前に初期化されなければなりません。 zalloc と zfree が Z_NULL のとき、デフォルトのライブラリ関数のメモリ確保ルーチンを使います。windowBits は
window サイズの 2を底とした対数で、8〜15の間です。window は呼び出し側から提供されたバッファサイズのそれです。小さな ウィンドウサイズを使う deflate を保証するような特別なアプリケーションを除いて は、
一般的な deflate ストリームで圧縮できるようにしなければならないときは windowBits が15 で window32Kバイトでなければなりません。

これらのルーチンについては inflateBack() を見てください

inflateBackInit は成功時 Z_OK を返すはずです、Z_STREAM_ERROR ならパラメータが全部無効、Z_MEM_ERROR なら内部でメモリ確保失敗、また Z_VERSION_ERROR ならライブラリ・バージョンがヘッダファイルと合致しない事を示します。
*/


/*
ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, unsigned char FAR *window));

Initialize the internal stream state for decompression using inflateBack() calls. The fields zalloc, zfree and opaque in strm must be initialized before the call. If zalloc and zfree are Z_NULL, then the default library-derived memory allocation routines are used. windowBits is the base two logarithm of the window size, in the range 8..15. window is a caller supplied buffer of that size. Except for special applications where it is assured that deflate was used with small window sizes, windowBits must be 15 and a 32K byte window must be supplied to be able to decompress general deflate streams.

See inflateBack() for the usage of these routines.

inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of the paramaters are invalid, Z_MEM_ERROR if the internal state could not be allocated, or Z_VERSION_ERROR if the version of the library does not match the version of the header file.
*/


typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));

ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc));
/*
inflateBack() は入出力用コールバック・インタ−フェースを使っている単独関数を伴う未処理 inflate を処理します。
単純に出力バッ ファに window を書き込んでいる最中の window と、その出力の間に、コピーするのを防ごうとするファイルI/Oアプリケーションの inflate() より、この関の方が効率がいいです。この関数は、少なくとも inflateBack() が返るまでは、出力関数によって通過された出力バッファをアプリケーションが変更しないことを前提としています。

inflateBackInit() は内部のメモリ確保とユーザ供給の
window バッファを含めたデータの初期化をするため最初に呼ばれなければなりません。inflateBack() は完全に inflate するため複数回呼ばれると思われますが、そのとき毎回未処理の deflate が必要です。その後inflateBackEnd() が確保したメモリを解放するため呼ばれます。

未処理の deflate ストリームというのは zlib や gzip ヘッダやトレイラを含まないものを指します。このルーチンは通常 zlib や gzip ファイルの読込や、非圧縮ファイルを書き出すユーティリティの中で使われます。そのユーティリティはヘッダをデコードし、それ自身のトレイラを処理 します。それゆえにこのルーチンは展開時に未処理の deflate ストリームだけを推測しています。これは inflate() の通常の動作と異なり、deflate ストリームを囲む
ヘッダとトレイラが zlib と gzip のどちらかということを推測します

入出力用に inflateBack() を呼ばれたとき、inflateBack() は呼び出し側に供給された2つのサブルーチンを使います。inflateBack() は、 deflate ストリームを完全に読み込み非圧縮データの全て書き出してしまうか、またはエラーがでるまで、それらのルーチンを呼びます。その関数の引数と返り値の 型は in_func と out_func typedef の中で上記で定義されてます。inflateBack() は、 in(in_desc, &buf) を buf に入力ポインタが入り、供給された入力のバイト数が返るように呼びます。入力が無効ならin() は必ずゼロを返します〜この場合 buf は無視されます〜そして inflateBack() はバッファエラーを返します。inflateBack() は非圧縮データ buf[0..len-1] を書き出すために out(out_desc, buf, len) を呼びます。out() は成功時ゼロを返し、失敗したら非ゼロです。out() が非ゼロを返したとき inflateBack() もエラーを返します。in() も out() も inflateBackInit() に供給されたウィンドウの中身を変更することは許可されてません。バッファは out() の書き出しにもまた使います。out() の書き出し長は長くてウィンドウ・サイズです。 in()
は必ずゼロでない入力量を供給するはずです。

簡便のため inflateBack() は最初の呼び出し時にstrm->next_in と strm->avail_in をセットすることで入力を得ることができます。入力を使い切ったら in() を呼びます。それゆえ strm->next_in は inflateBack() を呼ぶ前に必ず初期化されなければなりません。
strm->next_in が Z_NULL なら、in() が入力のため直ぐに呼ばれます。
strm->next_in が Z_NULL でないなら、strm->avail_in も期化されていなければならず、そしてそのとき strm->avail_in がゼロでないなら、入力は冒頭で strm->next_in[0 .. strm->avail_in - 1] から取得されます。

inflateBack() の in_desc と out_desc 引数は in() と out() が呼ばれるときそれぞれの第一引数として渡されます。これは、呼び出し側指定のの in() と out() 関数に、各処理で必要な情報を
追加で渡せるように使えることを示してします。

関数が返る時、inflateBack() は最後の in() 関数で供給された未使用の入力を返すため strm->next_in と strm->avail_in をセットします。inflateBack() の返り値は、成功時 Z_STREAM_END になリ得ます。Z_BUF_ERROR なら in() か out() がエラーを返してます。Z_DATA_ERROR なら deflate ストリームでフォーマットエラーがあった(この場合 strm->msg はエラーの性質を示すようセットされています)
事を示します。また、Z_STREAM_ERROR ならストリームがきちんと初期化されていません。Z_BUF_ERROR の場合、in() がエラーを返したときだけ Z_NULL になるstrm->next_in を使って、入力や出力エラーがはっきり分かります。strm->next が Z_NULL でないなら、Z_BUF_ERROR は out() が非ゼロを返したためです(in() はいつも out() の前に呼ばれるので out() が非ゼロを返したとき、strm->next_in が定義されることは確実です)。
inflateBack() が Z_OK を返せないことに注意してください。
*/


typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));

ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc));
/*
inflateBack() does a raw inflate with a single call using a call-back interface for input and output. This is more efficient than inflate() for file i/o applications in that it avoids copying between the output and the sliding window by simply making the window itself the output buffer. This function trusts the application to not change the output buffer passed by the output function, at least until inflateBack() returns.

inflateBackInit() must be called first to allocate the internal state and to initialize the state with the user-provided window buffer. inflateBack() may then be used multiple times to inflate a complete, raw deflate stream with each call. inflateBackEnd() is then called to free the allocated state.

A raw deflate stream is one with no zlib or gzip header or trailer. This routine would normally be used in a utility that reads zip or gzip files and writes out uncompressed files. The utility would decode the header and process the trailer on its own, hence this routine expects only the raw deflate stream to decompress. This is different from the normal behavior of inflate(), which expects either a zlib or gzip header and trailer around the deflate stream.

inflateBack() uses two subroutines supplied by the caller that are then called by inflateBack() for input and output. inflateBack() calls those routines until it reads a complete deflate stream and writes out all of the uncompressed data, or until it encounters an error. The function's parameters and return types are defined above in the in_func and out_func typedefs. inflateBack() will call in(in_desc, &buf) which should return the number of bytes of provided input, and a pointer to that input in buf. If there is no input available, in() must return zero--buf is ignored in that case--and inflateBack() will return a buffer error. inflateBack() will call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() should return zero on success, or non-zero on failure. If out() returns non-zero, inflateBack() will return with an error. Neither in() nor out() are permitted to change the contents of the window provided to inflateBackInit(), which is also the buffer that out() uses to write from. The length written by out() will be at most the window size. Any non-zero amount of input may be provided by in().

For convenience, inflateBack() can be provided input on the first call by setting strm->next_in and strm->avail_in. If that input is exhausted, then in() will be called. Therefore strm->next_in must be initialized before calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in must also be initialized, and then if strm->avail_in is not zero, input will initially be taken from strm->next_in[0 .. strm->avail_in - 1].

The in_desc and out_desc parameters of inflateBack() is passed as the first parameter of in() and out() respectively when they are called. These descriptors can be optionally used to pass any information that the caller-supplied in() and out() functions need to do their job.

On return, inflateBack() will set strm->next_in and strm->avail_in to pass back any unused input that was provided by the last in() call. The return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR if in() or out() returned an error, Z_DATA_ERROR if there was a format error in the deflate stream (in which case strm->msg is set to indicate the nature of the error), or Z_STREAM_ERROR if the stream was not properly initialized. In the case of Z_BUF_ERROR, an input or output error can be distinguished using strm->next_in which will be Z_NULL only if in() returned an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to out() returning non-zero. (in() will always be called before out(), so strm->next_in is assured to be defined if out() returns non-zero.) Note that inflateBack() cannot return Z_OK.
*/


ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm));
/*
inflateBackInit() が確保したメモリを全て解放します。

inflateBackEnd() の返り値は、Z_OK なら成功、また Z_STREAM_ERROR ならストリーム状態が異常です。
*/


ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm));
/*
All memory allocated by inflateBackInit() is freed.

inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream state was inconsistent.
*/


ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
/* コンパイル・タイム オプションが示す返り値フラグ

サイズ・タイプ、2ビット毎、00 = 16 ビット, 01 = 32, 10 = 64, 11 = その他:
1.0: size of uInt
3.2: size of uLong
5.4: size of voidpf (ポインタ)
7.6: size of z_off_t

コンパイラ、アセンブラ、及びデバッグ・オプション:
8: DEBUG
9: ASMV か ASMINF -- ASM コード使用
10: ZLIB_WINAPI -- WINAPI が呼ぶ規約をエクスポート関数で使用します。
11: 0 (予約済み)

一発テーブル・ビルド(小さくなるコードですが、もし true ならスレッドセーフではありません):
12: BUILDFIXED -- 要求されたときデコード・テーブルを静的ブロックでビルドします。
13: DYNAMIC_CRC_TABLE -- 要求されたとき CRC 計算テーブルをビルドします。
14,15: 0 (予約済み)

ライブラリ・コンテンツ(関数以外の記述):
16: NO_GZCOMPRESS -- gz* 関数は圧縮できない(要求されないとき deflate コードにリンク
しないようにします
17: NO_GZIP -- deflate は gzip ストリームを書き出せず、inflate は gzip ストリームを探知もデコードもできません。(crc コードにリンクしないようにします)
18-19: 0 (予約済み)

命令バリエーション(ライブラリ関数内の変更):
20: PKZIP_BUG_WORKAROUND -- 少しばかり自由な inflate
21: FASTEST -- 最も低い圧縮レベルをひとつだけ伴う deflate アルゴリズム
22,23: 0 (予約済み)

gzprintf が使う sprintf の異種(ゼロがベストです):
24: 0 = vs*, 1 = s* -- 1 が意味するのは後のフォーマットで
引数 は 20 個が限界ですということです。
25: 0 = *nprintf, 1 = *printf -- 1 の意味は gzprintf() は安全ではありません!

26: 0 = 返り値、1 = void -- 1 は文字列長が返されたことを暗示しています。

残り:
27-31: 0 (予約済み)
*/


ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
/* Return flags indicating compile-time options.

Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
1.0: size of uInt
3.2: size of uLong
5.4: size of voidpf (pointer)
7.6: size of z_off_t

Compiler, assembler, and debug options:
8: DEBUG
9: ASMV or ASMINF -- use ASM code
10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
11: 0 (reserved)

One-time table building (smaller code, but not thread-safe if true):
12: BUILDFIXED -- build static block decoding tables when needed
13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
14,15: 0 (reserved)

Library content (indicates missing functionality):
16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking deflate code when not needed)
17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect and decode gzip streams (to avoid linking crc code)
18-19: 0 (reserved)

Operation variations (changes in library functionality):
20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
21: FASTEST -- deflate algorithm with only one, lowest compression level
22,23: 0 (reserved)

The sprintf variant used by gzprintf (zero is best):
24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
26: 0 = returns value, 1 = void -- 1 means inferred string length returned

Remainder:
27-31: 0 (reserved)
*/



/* ユーティリティ関数 */

/*
下記ユーティリティ関数は基本ストリーム向け関数の最上位に位置しています。インターフェースを簡易化するために、いくつかデフォルト・オプション
(圧縮レベルとメモリ使用、標準メモリ確保関数)が用意 されています。これらのユーティリティ関数のソースコードは、ユーザが特殊なオプションをつけたいと思え ば間単につけられます。
*/

/* utility functions */

/*
The following utility functions are implemented on top of the basic stream-oriented functions. To simplify the interface, some default options are assumed (compression level and memory usage, standard memory allocation functions). The source code of these utility functions can easily be modified if you need special options.
*/

ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen));
/*
圧縮元バッファを圧縮し、圧縮先バッファに格納します。sourceLen は圧縮元バッファのバイト長です。関数開始時、少なくとも destLen はcompressBound(sourceLen) で返った値でなければならず、圧縮先バッファのトータル・サイズです。関数終了時、destLen には圧縮されたバッファの実際のサイズがはいってます。この関数は、入力ファイルがmmapされている時など一度にファイルまるごと圧縮するのに使われま す。
compress の返り値は、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_BUF_ERROR なら出力バッファに十分な空きがありません。
*/


ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen));
/*
Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least the value returned by compressBound(sourceLen). Upon exit, destLen is the actual size of the compressed buffer. This function can be used to compress a whole file at once if the input file is mmap'ed. compress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer.
*/


ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level));
/*
圧縮元バッファを圧縮し、圧縮先バッファに格納します。
level 引数は deflateInit 内と同様の意味を持ちます。sourceLen は 圧縮元バッファのバイト長です。関数開始時、destLen は圧縮先バッファのトータル・サイズであり、少なくとも compressBound(sourceLen) で返った値でなければなりません。関数終了時、destLen には圧縮されたバッファの実際のサイズがはいってます。

compress2 の返り値は、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_BUF_ERROR なら出力バッファに十分な空きがありません。 Z_STREAM_ERROR なら
level 引数が無効です。
*/


ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level));
/*
Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least the value returned by compressBound(sourceLen). Upon exit, destLen is the actual size of the compressed buffer.

compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, Z_STREAM_ERROR if the level parameter is invalid.
*/


ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
/*
compressBound() は sourceLen バイト上に compress() や compress2() 後の圧縮されたサイズの上限値を返します。それはcompress() や compress2() を呼ぶ前に、圧縮先バッファのメモリ確保するために使われます。
*/


ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
/*
compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer.
*/


ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen));
/*
展開元バッファを展開し、展開先バッファに格納します。sourceLen は展開元バッファのバイト長です。関数開始時、destLen は展開先バッファのトータル・サイズで、非圧縮データを丸ごと保持するため十分大きくなければなりません。
(その非圧縮データのサイズはあらかじめ圧縮関数によって保存されていなければならず、そしてこの圧縮ライブラリではない外部のシステムで、展開関 数に伝えられていなければなりません。関数終了時、destLen には圧縮されたバッファの実際のサイズがはいってます。この関数は、入力ファイルがmmapされてるとき一度にファイルまるごと展開するのに使われます。

uncompress の返り値は、Z_OK なら成功、Z_MEM_ERROR ならメモリ不足、Z_BUF_ERROR なら出力バッファに十分な空きがありません。また Z_DATA_ERROR なら入力データが壊れているか不完全です。
*/


ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, destLen is the actual size of the compressed buffer. This function can be used to decompress a whole file at once if the input file is mmap'ed.

uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
*/


typedef voidp gzFile;

ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
/*
gzip(.gz)ファイルを読み出しや書き出し用に開きます。
mode 引数は fopen ("rb" や "wb") と同様ですが、圧縮レベル("wb9")といったもの やまたある方法もまた使えます… 'f' はフィルターデータを表し "wb6f" のように使います、また 'h' はハフマン法だけを使った圧縮で "wb1h" のように使います、また 'R' はランレンクス・エンコードを表し "wb1R"のように 使います。 (引数の使い方についての詳しい情報は、deflateInit2 の記述を見てください。)

gzopen は gzip フォーマットでないファイルの読込にも使えます…この場合 gzread は展開せずに直接ファイルから読み込みます。

gzopen が NULL を返したら、ファイルを開けなかったか、または(展開)圧縮におけるメモリ不足です… errno から2つの場合を識別確認できます(errno がゼロなら、zlib エラーは Z_MEM_ERROR です)。 */


typedef voidp gzFile;

ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter is as in fopen ("rb" or "wb") but can also include a compression level ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman only compression as in "wb1h", or 'R' for run-length encoding as in "wb1R". (See the description of deflateInit2 for more information about the strategy parameter.)

gzopen can be used to read a file which is not in gzip format; in this case gzread will directly read from the file without decompression.

gzopen returns NULL if the file could not be opened or if there was insufficient memory to allocate the (de)compression state; errno can be checked to distinguish the two cases (if errno is zero, the zlib error is Z_MEM_ERROR). */


ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() は gzFile をファイル記述子 fd と結び付けます。ファイル記述子はopen, dup, creat, pipe や fileno(fopen であらかじめ開いたファイル内で)のような関数から得られます。
mode 引数は gzopen のものと同様です。gzFile が返った時は次に gzclose の呼び出すことでファイル記述子 fd を閉じることもします。まさに fclose(fdopen(fd), mode) のようにファイル記述子 fd を閉じます。fd を開いたままにしたいなら、gzdopen(dup(fd), mode)を使います。
gzdopen がNULL を返したら、(展開)圧縮におけるメモリ不足です。
*/


ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (in the file has been previously opened with fopen). The mode parameter is as in gzopen. The next call of gzclose on the returned gzFile will also close the file descriptor fd, just like fclose(fdopen(fd), mode) closes the file descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). gzdopen returns NULL if there was insufficient memory to allocate the (de)compression state.
*/


ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
圧縮レベルや圧縮方法を動的に更新します。引数の意味は deflateInit2 の記述を見てください。gzsetparams の返り値は、Z_OK なら成功、また Z_STREAM_ERROR ならファイルが書き出し用に開かれていません。
*/

ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
Dynamically update the compression level or strategy. See the description of deflateInit2 for the meaning of these parameters. gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not opened for writing.
*/

ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
圧縮されたファイルから与えられた展開バイト数を読み込みます。入力ファイルが gzip フォーマットでないなら、gzread は与えられたバイト数をバッファにコピーします。
gzread は実際に読み込んだ非圧縮バイト数を返します(0 ならファイル終端、-1ならエラー)。 */


ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file. If the input file was not in gzip format, gzread copies the given number of bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for end of file, -1 for error). */

ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len));
/*
圧縮されたファイルに与えられた展開バイト数を書き込みます。gzwrite は実際に書き込んだ展開バイト数を返します(0 ならエラー)。
*/

ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len));
/*
Writes the given number of uncompressed bytes into the compressed file. gzwrite returns the number of uncompressed bytes actually written (0 in case of error).
*/

ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/*
fprintf フォーマット同様に、圧縮ファイルに引数を文字列形式のコントロールから変換し、フォーマットし、書込みます。gzprintf は実際に書き込んだ展開バイト数を返します(0 ならエラー)。書き込んだ展開バイト数の限界は4095 です。呼び出し側は限界を
確実に超 えないようしてください。限界を超えた場合 何も書き込まれず、gzprintf() は error (0) を返します。この場合、予測できない結果を伴うバッファ・オーバーフローにも起こり得ります。これは zlib が安全でない関数 sprintf() や vsprintf() を伴いコンパイルされた時だけ起こりえます。なぜなら安全な snprintf() や vsnprintf()が有効でないからです。
*/


ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the args to the compressed file under control of the format string, as in fprintf. gzprintf returns the number of uncompressed bytes actually written (0 in case of error). The number of uncompressed bytes written is limited to 4095. The caller should assure that this limit is not exceeded. If it is exceeded, then gzprintf() will return return an error (0) with nothing written. In this case, there may also be a buffer overflow with unpredictable consequences, which is possible only if zlib was compiled with the insecure functions sprintf() or vsprintf() because the secure snprintf() or vsnprintf() functions were not available.
*/


ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/*
圧縮ファイルに null 終端の文字列を終端のnull 文字を含めずに書き込みます。
gzputs は書き込まれた文字数を返します。また -1 ならエラーです。
*/


ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/*
Writes the given null-terminated string to the compressed file, excluding the terminating null character. gzputs returns the number of characters written, or -1 in case of error.
*/


ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/*
圧縮ファイルから読み込まれた len-1 文字までか、改行文字を読み込み buf に転送するまでか、またeof が見つかるまで、読み込みます。
そのとき文字列は null 文字で終端します。gzgets は buf を返します。また Z_NULL が返ったらエラーです。
*/


ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/*
Reads bytes from the compressed file until len-1 characters are read, or a newline character is read and transferred to buf, or an end-of-file condition is encountered. The string is then terminated with a null character.
gzgets returns buf, or Z_NULL in case of error.
*/


ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/*
引数 c を unsigned char に 変換し圧縮ファイルに書き込みます。gzputc は書き込まれた値を返します。-1 が返ったらエラーです。
*/


ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/*
Writes c, converted to an unsigned char, into the compressed file. gzputc returns the value that was written, or -1 in case of error.
*/


ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
圧縮ファイルから 1バイト読み込ます。gzgetc はこのバイトを返すか、エラーかファイル終端なら -1 を返します。
*/


ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte or -1 in case of end of file or error.
*/


ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
/*
1文字だけストリーム上に押し戻し、後から再び読み込めるようにします。押し戻せるのは1文字だけです。gzungetc() は押し戻した文字を返すか、失敗時は -1 を返します。gzungetc() が失敗したときは、
押し戻されませんが、それはまだ読込がされていないか、または c が -1のときです。ストリームが gzseek() や gzrewind() で再配置されたときは押し戻された文字は破棄されます。
*/


ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
/*
Push one character back onto the stream to be read again later. Only one character of push-back is allowed. gzungetc() returns the
character pushed, or -1 on failure. gzungetc() will fail if a
character has been pushed but not read yet, or if c is -1.The pushed
character will be discarded if the stream is repositioned with gzseek() or gzrewind().
*/


ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/*
未処理の出力を全て圧縮ファイルにフラッシュします。
flush 引数は deflate() 同様です。返り値は zlib のエラー番号です(下記の gzerror 関数を見てください)。 gzflush の返り値は、Z_OK ならフラッシュ・パラメータが Z_FINISH で全てされた事を示します。圧縮率が劣化し得るので gzflush は本当に必要なときだけ呼ぶようにして下さい。
*/


ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter flush is as in the deflate() function. The return value is the zlib error number (see function gzerror below). gzflush returns Z_OK if the flush parameter is Z_FINISH and all output could be flushed.
 gzflush should be called only when strictly necessary because it can degrade compression.
*/


ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, z_off_t offset, int whence));
/*
渡された圧縮ファイル上で次の gzread や gzwrite のためスタート位置をセットします。offset は展開ストリーム内のバイト数を表しています。whence 引数は lseek(2) 内のものと同じように使ってください… SEEK_END 値はサポートされません。
ファイルが読込用に開かれたときこの関数はエミュレートされますが、極端に遅くなることがあります。ファイルが書込用に開かれたとき、前方 seek しかサポートされません
このとき gzseek は、新しいスタート位置をゼロ位置としてシーケンスを圧縮します

gzseek 展開ストリームの始点からのオフセット位置をバイト値のような値で返します、また -1を返した場合はエラーです。とりわけファイルが書き込み用に開かれているとき新しいスタート位置はカレント・ポジションになるはずです。
*/


ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, z_off_t offset, int whence));
/*
Sets the starting position for the next gzread or gzwrite on the given compressed file. The offset represents a number of bytes in the uncompressed data stream. The whence parameter is defined as in lseek(2); the value SEEK_END is not supported.
If the file is opened for reading, this function is emulated but can be extremely slow. If the file is opened for writing, only forward seeks are supported; gzseek then compresses a sequence of zeroes up to the new starting position.

gzseek returns the resulting offset location as measured in bytes from the beginning of the uncompressed stream, or -1 in case of error, in particular if the file is opened for writing and the new starting position would be before the current position.
*/


ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/*
与えられたファイルを巻き戻しします。この関数は読込時のみサポートされます。

gzrewind(file) は (int)gzseek(file, 0L, SEEK_SET) と同等です。
*/


ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/*
Rewinds the given file. This function is supported only for reading.

gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
*/


ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
圧縮ファイル上で次の gzread や gzwrite のためにスタート位置を返します。この位置は非圧縮データストリーム内のバイト数です。


gztell(file) は gzseek(file, 0L, SEEK_CUR) と同等です。
*/


ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
Returns the starting position for the next gzread or gzwrite on the given compressed file. This position represents a number of bytes in the uncompressed data stream.

gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/


ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/*
与えられた入力ストリームで前もって EOF が検出されていたとき 1 を返し、そうでなければ 0 を返します。
*/


ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/*
Returns 1 when EOF has previously been detected reading the given input stream, otherwise zero.
*/


ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/*
必要に応じて未処理の出力をフラッシュし、圧縮ファイルを閉じ、全ての(展開)圧縮用メモリを解放します。返り値は zlib エラー番号です(下記の gzerror 関数を見てください)。
*/


ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file and deallocates all the (de)compression state. The return value is the zlib error number (see function gzerror below).
*/


ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/*
圧縮ファイル上で起こった最終エラーのエラーメッセージを返します。errnum は zlib エラー番号です。もしエラーが圧縮ライブラリではなくファイルシステムで起こったのなら、errnum には Z_ERRNO がセットされ、アプリケーションが正確なエラーコードを得るには errno を調べることになります。
*/


ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the given compressed file. errnum is set to zlib error number. If an error occurred in the file system and not in the compression library, errnum is set to Z_ERRNO and the application may consult errno to get the exact error code.
*/


ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
/*
エラーとファイルの
end-of-file フラグを消去します。これは stdio の clearerr() 関数に類似しています。これはgzip ファイルの書込みを同時に行う読込を続けるのに役立ちます。
*/


ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
/*
Clears the error and end-of-file flags for file. This is analogous to the clearerr() function in stdio. This is useful for continuing to read a gzip file that is being written concurrently.
*/


/* チェックサム関数 */

/*
これらの関数は圧縮とは関連しませんが、圧縮ライブラリを使うアプリケーションに役立つはずなので、どうしてもエクスポートされます。
*/


/* checksum functions */

/*
These functions are not related to compression but are exported anyway because they might be useful in applications using the compression library.
*/


ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));

/*
実行中の Adler-32 チェックサムをバイトbuf[0..len-1] で更新し、その更新されたチェックサムを返します。buf が NULL ならこの関数はチェックサム用に要求された初期値を返します。
Adler-32 チェックサムは大体 CRC32 と同じくらいの信頼性がありますが、かなり速く計算することができます。使用例:

    uLong adler = adler32(0L, Z_NULL, 0);

    while (read_buffer(buffer, length) != EOF) {
       adler = adler32(adler, buffer, length);
    }
i    f (adler != original_adler) error();
*/


ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));

/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. If buf is NULL, this function returns the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much faster. Usage example:

    uLong adler = adler32(0L, Z_NULL, 0);

    while (read_buffer(buffer, length) != EOF) {
       adler = adler32(adler, buffer, length);
    }
i    f (adler != original_adler) error();
*/


ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
実行中の crc をバイトbuf[0..len-1] で更新し、その更新された crc を返します。buf が NULL ならこの関数は crc 用に要求された初期値を返します。事前条件と事後条件(ひとつの補完)はこの関数内部で実行されるのでアプリケーションは実行すべきではありません。使用 例:

    uLong crc = crc32(0L, Z_NULL, 0);

    while (read_buffer(buffer, length) != EOF) {
        crc = crc32(crc, buffer, length);
    }
    if (crc != original_crc) error();
*/



ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running crc with the bytes buf[0..len-1] and return the updated crc. If buf is NULL, this function returns the required initial value for the crc. Pre- and post-conditioning (one's complement) is performed within this function so it shouldn't be done by the application. Usage example:

    uLong crc = crc32(0L, Z_NULL, 0);

    while (read_buffer(buffer, length) != EOF) {
        crc = crc32(crc, buffer, length);
    }
    if (crc != original_crc) error();
*/



       /* 何でも書き、見ちゃダメです  (^o^) */

/* deflateInit と inflateInit は zlib バージョンをチェックさせるマクロです。
* あと z_stream のコンパイラ・ビューです:
*/

ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, const char *version, int stream_size));
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel,
int strategy, const char *version,
int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
unsigned char FAR *window,
const char *version,
int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#define inflateBackInit(strm, windowBits, window) \
inflateBackInit_((strm), (windowBits), (window), \
ZLIB_VERSION, sizeof(z_stream))


#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* コンパイル・バグ回避 */
#endif

ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));

#ifdef __cplusplus
}
#endif

#endif /* ZLIB_H */
/* various hacks, don't look :) */

/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/

ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, const char *version, int stream_size));
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel,
int strategy, const char *version,
int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
unsigned char FAR *window,
const char *version,
int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#define inflateBackInit(strm, windowBits, window) \
inflateBackInit_((strm), (windowBits), (window), \
ZLIB_VERSION, sizeof(z_stream))


#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif

ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));

#ifdef __cplusplus
}
#endif

#endif /* ZLIB_H */




戻る