[57] zlib は、 DEFLATE を用いる圧縮形式です。
[58] zlib は RFC 1950 により定義されています。
[27] zlib stream は、次のようなバイト列です。
[35] 入力データの長さが不十分なときにどう処理するべきかは不明です。
[72] RFC 6713 は zlib を識別する魔法数として、
... を挙げています >>70。
[28] CM (Compression method) は、 圧縮方式を表します。 >>20
[29] 8 は、 DEFLATE (窓サイズ 32KB 以下) を表します。 >>20
[30] 15 は、予約されています。 将来の版で、圧縮データ前に追加の欄が存在することを示すために使うかもしれません。 >>20
[38] FCHECK は、 CMF と FLG の検査ビットであり、 CMF × 256 × FLG が 31 の倍数となるような値に設定しなければなりません。 >>20
[39] 展開器は FLG を検査しなければならない >>20 とされていますが、 不正なデータをどう処理するべきかは不明です。
[40] FDICT は、 設定されている場合、 DICTID が FLG の直後に現れることを表します。 >>20
[54] zlib を用いるデータ形式が preset dictionary を用いない場合、 圧縮器は FDICT を設定してはなりません。展開器は拒絶しなければなりません。 >>20
[44] FLEVEL (圧縮レベル) は、圧縮方式依存です。 >>20
[45] CM が 8 の場合、次の通りの意味です。 >>20
[47] この情報は再圧縮する意味があるかどうかの判断に使えます。 >>20
[41] FDICT ビットが設定されている場合、 DICTID (辞書識別子 >>20) を記述します。
[42] 辞書 (preset dictionary) とは、 最初に圧縮器に与えるバイト列で、圧縮データ自体ではないものです。 DICTID は、このバイト列の Adler-32 検査和です。 >>20
[53] 他のデータ形式が zlib を用いる時、 圧縮器はそのデータ形式が定めた preset dictionary を用いて構いません。 展開器はそのすべての preset dictionary に対応しなければなりません。 >>20
[43] 展開器は、この DICTID を使ってどの preset dictionary が使われているかを判断できます。 >>20
[55] 展開器は、 FDICT が設定されていて DICTID が未知の preset dictionary の場合、エラーとしなければなりません。 >>20
[48] 圧縮データ >>20 は、 圧縮された実際のデータです。
[51] ADLER32 (Adler-32 検査和) は、 未圧縮データ (辞書データを含みません。) について Adler-32 検査和を計算したものです。 >>20
[56] 展開器は ADLER32 を検査しなければならない >>20 とされていますが、 不適切な場合どう処理するべきかは不明です。
[34] それ以後にデータがあったとしても、 zlib stream の一部ではありません。 >>20
[22] 圧縮器は、 RFC 1950 のすべての要件を満たすデータを生成しなければなりません。 >>20
[52] preset dictionary に対応する義務はありません。 >>20
[71] MIME型として application/zlib
が
RFC 6713 で定義されています >>70。
[18] データ形式としての ZLIB は次の場面で用いられています。
deflate
#✎[3] 内容符号化・転送符号化 deflate
は、
LZ77 圧縮法とハフマン符号化の組み合わせを用いた RFC 1951
「deflate」圧縮データストリームを含んだ RFC 1950
「zlib」データ形式を表します >>2, >>6, >>7。
[4] 実装によっては zlib を用いない DEFLATE 圧縮データを
deflate
として送りますが、これは不適合 >>2 とされています。
[61] zlib のドキュメントは、
Microsoft などいくつかのサーバーとブラウザーが誤って
deflate
を DEFLATE の意味で使っているため、
gzip
を使う方がおそらくより信頼性が高いだろうと指摘しています >>60。
[25] 3.2 版で用語の変更と Adler-32 コード例の改訂がありました。 >>20
[26] 3.3 版で preset dictionary が導入され、 RFC 化されました。 >>20
deflate
#✎[14] 実現値操作 deflate
は、
内容符号化 deflate
と同じです >>13。
[16] gdiff
や diffe
は圧縮によって大きくサイズを削減できますから、
deflate
も実装することが強く推奨されています >>15。
[89] 実現値操作 deflate
はIANA登録簿には RFC 2616 を出典として登録されています >>88。
RFC 723x 出版後も出典は更新されていません。
[21] ランダムアクセスは設計上の想定外とされています >>20。
[11] zlib Home Site ( ( 版)) http://www.zlib.net/
[12] zlib - Wikipedia ( 版) https://ja.wikipedia.org/wiki/Zlib
[1] java - Handling HTTP ContentEncoding "deflate" - Stack Overflow ( 版) http://stackoverflow.com/questions/3932117/handling-http-contentencoding-deflate
[8] IE7 – Deflate or Not? – Subbu Allamaraju ( 版) https://www.subbu.org/blog/2008/03/ie7-deflate-or-not
[9] Deflate - Wikipedia ( 版) https://ja.wikipedia.org/wiki/Deflate
[10] RFC 6713 - The 'application/zlib' and 'application/gzip' Media Types ( 版) https://tools.ietf.org/html/rfc6713
"gzip" is the gzip format, and "deflate" is the zlib format. They should probably have called the second one "zlib" instead to avoid confusion with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 correctly points to the zlib specification in RFC 1950 for the "deflate" transfer encoding, there have been reports of servers and browsers that incorrectly produce or expect raw deflate data per the deflate specficiation in RFC 1951, most notably Microsoft. So even though the "deflate" transfer encoding using the zlib format would be the more efficient approach (and in fact exactly what the zlib format was designed for), using the "gzip" transfer encoding is probably more reliable due to an unfortunate choice of name on the part of the HTTP 1.1 authors.
require IO::Uncompress::Inflate;
my $output;
my $status = IO::Uncompress::Inflate::inflate($content_ref, \$output, Transparent => 0);
my $error = $IO::Uncompress::Inflate::InflateError;
unless ($status) {
# "Content-Encoding: deflate" is supposed to mean the
# "zlib" format of RFC 1950, but Microsoft got that
# wrong, so some servers sends the raw compressed
# "deflate" data. This tries to inflate this format.
$output = undef;
require IO::Uncompress::RawInflate;
unless (IO::Uncompress::RawInflate::rawinflate($content_ref, \$output)) {
$self->push_header("Client-Warning" =>
"Could not raw inflate content: $IO::Uncompress::RawInflate::RawInflateError");
$output = undef;
}
}
The deflate encoding is not supported, please check the zlib's documentation for a complete explanation.
[68] Content-Encoding: deflate is actually zlib · Issue #46 · valyala/fasthttp () https://github.com/valyala/fasthttp/issues/46
[69] Re: Content-Encoding: deflate - is this zlib file format? (Daniel Barron著, ) https://lists.w3.org/Archives/Public/www-talk/2001SepOct/0015.html