zlib、gzip、zip はどのように関連していますか? 共通点と相違点は何ですか? 質問する

zlib、gzip、zip はどのように関連していますか? 共通点と相違点は何ですか? 質問する

zlibで使用される圧縮アルゴリズムは、gzipzipのものと基本的に同じですgzipzipとは何ですか? それらはどう異なり、どう同じですか?

ベストアンサー1

ショートフォーム:

.zipアーカイブ形式です通常は、圧縮方式をデフレートする.gzgzip形式は単一ファイル用で、これもDeflate圧縮方式を使用します。gzipは多くの場合、圧縮アーカイブ形式を作成するためのtar.tar.gzzlib ライブラリzip、gzipで使用するためのDeflate圧縮および解凍コードを提供します。png(これはzlib ラッパーdeflate データなど、さまざまなアプリケーションで使用できます。

長い形式:

ZIP形式は、オープン仕様のオープン フォーマットとして Phil Katz によって開発されました。彼の実装である PKZIP はシェアウェアでした。これは、ファイルとそのディレクトリ構造を保存するアーカイブ フォーマットで、各ファイルは個別に圧縮されます。ファイルの種類は です.zip。ファイルとディレクトリ構造は、オプションで暗号化できます。

ZIP 形式では、いくつかの圧縮方法をサポートしています。

    0 - The file is stored (no compression)
    1 - The file is Shrunk
    2 - The file is Reduced with compression factor 1
    3 - The file is Reduced with compression factor 2
    4 - The file is Reduced with compression factor 3
    5 - The file is Reduced with compression factor 4
    6 - The file is Imploded
    7 - Reserved for Tokenizing compression algorithm
    8 - The file is Deflated
    9 - Enhanced Deflating using Deflate64(tm)
   10 - PKWARE Data Compression Library Imploding (old IBM TERSE)
   11 - Reserved by PKWARE
   12 - File is compressed using BZIP2 algorithm
   13 - Reserved by PKWARE
   14 - LZMA
   15 - Reserved by PKWARE
   16 - IBM z/OS CMPSC Compression
   17 - Reserved by PKWARE
   18 - File is compressed using IBM TERSE (new)
   19 - IBM LZ77 z Architecture 
   20 - deprecated (use method 93 for zstd)
   93 - Zstandard (zstd) Compression 
   94 - MP3 Compression 
   95 - XZ Compression 
   96 - JPEG variant
   97 - WavPack compressed data
   98 - PPMd version I, Rev 1
   99 - AE-x encryption marker (see APPENDIX E)

方法 1 から 7 は歴史的なものであり、現在使用されていません。方法 9 から 98 は比較的最近追加されたもので、使用頻度はさまざまですが、少量です。ZIP 形式で本当に広く使用されている唯一の方法は方法 8 です。収縮する、そして、ある程度は圧縮を行わない方法 0 もあります。実際に.zip目にするほぼすべてのファイルは、方法 8 と 0 のみを使用しており、おそらく方法 8 だけです。(方法 8 には、圧縮を行わず、比較的拡張を少なくしてデータを効果的に保存する手段もあります。方法 0 はストリーミングできませんが、方法 8 は可能です。)

ファイルコンテナの ISO/IEC 21320-1:2015 規格は、Java アーカイブ ファイル (.jar)、Office Open XML ファイル (Microsoft Office .docx、.xlsx、.pptx)、Office Document Format ファイル (.odt、.ods、.odp)、EPUB ファイル (.epub) などで使用される制限された zip 形式です。この標準では、圧縮方法が 0 と 8 に制限され、暗号化や署名がないなどの制約もあります。

1990年頃、Info-ZIPグループ移植可能で無料のオープンソースのzipおよびunzipユーティリティの実装を作成し、Deflate 形式による圧縮と、それ以前の形式の解凍をサポートしました。これにより、この.zip形式の使用が大幅に拡大しました。

90年代初頭、gzip形式の代替として開発されたUnixcompressユーティリティ、Info-ZIPユーティリティのDeflateコードから派生したものです。Unixは、ファイル名に をcompress追加して、単一のファイルまたはストリームを圧縮するように設計されています。.ZcompressLZW圧縮アルゴリズム, which at the time was under patent and its free use was in dispute by the patent holders. Though some specific implementations of Deflate were patented by Phil Katz, the format was not, and so it was possible to write a Deflate implementation that did not infringe on any patents. That implementation has not been so challenged in the last 20+ years. The Unix gzip utility was intended as a drop-in replacement for compress, and in fact is able to decompress compress-compressed data (assuming that you were able to parse that sentence). gzip appends a .gz to the file name. gzip uses the Deflate compressed data format, which compresses quite a bit better than Unix compress, has very fast decompression, and adds a CRC-32 as an integrity check for the data. The header format also permits the storage of more information than the compress format allowed, such as the original file name and the file modification time.

Though compress only compresses a single file, it was common to use the tar utility to create an archive of files, their attributes, and their directory structure into a single .tar file, and then compress it with compress to make a .tar.Z file. In fact, the tar utility had and still has the option to do the compression at the same time, instead of having to pipe the output of tar to compress. This all carried forward to the gzip format, and tar has an option to compress directly to the .tar.gz format. The tar.gz format compresses better than the .zip approach, since the compression of a .tar can take advantage of redundancy across files, especially many small files. .tar.gz is the most common archive format in use on Unix due to its very high portability, but there are more effective compression methods in use as well, so you will often see .tar.bz2 and .tar.xz archives.

Unlike .tar, .zip has a central directory at the end, which provides a list of the contents. That and the separate compression provides random access to the individual entries in a .zip file. A .tar file would have to be decompressed and scanned from start to end in order to build a directory, which is how a .tar file is listed.

Shortly after the introduction of gzip, around the mid-1990s, the same patent dispute called into question the free use of the .gif image format, very widely used on bulletin boards and the World Wide Web (a new thing at the time). So a small group created the PNG losslessly compressed image format, with file type .png, to replace .gif. That format also uses the Deflate format for compression, which is applied after filters on the image data expose more of the redundancy. In order to promote widespread usage of the PNG format, two free code libraries were created. libpng and zlib. libpng は PNG 形式のすべての機能を処理し、zlib は libpng や他のアプリケーションで使用するための圧縮および解凍コードを提供しました。zlib はコードから適応されましたgzip

上記の特許はすべて期限切れになっています。

zlibライブラリは、Deflate圧縮と解凍、およびDeflateストリームの3種類のラッピングをサポートしています。これらはラッピングなし(「生の」Deflate)です。zlib ラッピングは、PNG 形式のデータ ブロックで使用される と、プログラマーに gzip ルーチンを提供する gzip ラッピングです。zlib ラッピングと gzip ラッピングの主な違いは、zlib ラッピングの方がコンパクト (gzip の最小 18 バイトに対して 6 バイト) で、整合性チェックの Adler-32 は gzip が使用する CRC-32 よりも高速に実行されることです。Raw deflate は、.zipdeflate 圧縮データをラップする別の形式である形式を読み書きするプログラムによって使用されます。

zlibは現在、データの転送と保存に広く使用されています。たとえば、サーバーとブラウザによるほとんどのHTTPトランザクションは、zlibを使用してデータを圧縮および解凍します。具体的には、HTTPヘッダー手段Content-Encoding: deflateです。zlib データ形式内にラップされた deflate 圧縮方式

deflateの異なる実装は、同じ入力データに対して異なる圧縮出力をもたらす可能性があります。これは、圧縮効果とCPU時間をトレードオフできる選択可能な圧縮レベルが存在することからも明らかです。zlibとPKZIPは、deflate圧縮と解凍の唯一の実装ではありません。7-Zip アーカイブユーティリティそしてGoogleのzopfli ライブラリdeflate形式を使用する場合、zlibよりもはるかに多くのCPU時間を使用して、可能な限り最後の数ビットを絞り出すことができ、zlibの最高圧縮レベルと比較して圧縮サイズが数パーセント削減されます。pigz ユーティリティgzip の並列実装であるには、zlib (圧縮レベル 1 ~ 9) または zopfli (圧縮レベル 11) を使用するオプションが含まれており、大きなファイルの圧縮を複数のプロセッサとコアに分割することで、zopfli の使用による時間の影響をある程度軽減します。

おすすめ記事