zlibは圧縮の中でも、基本的なDeflate圧縮を行うライブラリ。
zlib Home Site
zlib 1.2.11 Manual
zlib 入門
テキストファイルをDeflate圧縮してみる。
その前に、
$ yum search zlib Fedora Modular 29 - x86_64 153 kB/s | 1.5 MB 00:09 Fedora Modular 29 - x86_64 - Updates 231 kB/s | 2.1 MB 00:09 Fedora 29 - x86_64 - Updates 1.7 MB/s | 30 MB 00:17 Fedora 29 - x86_64 1.8 MB/s | 62 MB 00:34 メタデータの期限切れの最終確認: 0:00:06 時間前の 2019年xx月xx日 xx時xx分xx秒 に実施しました。 ============================= 名前 完全一致: zlib ============================== zlib.i686 : The compression and decompression library zlib.x86_64 : The compression and decompression library ============================ 概要 & 名前 一致: zlib ============================ zlib-ada.x86_64 : Zlib for Ada jzlib-demo.noarch : Examples for jzlib tcl-zlib.i686 : Tcl extension for zlib support tcl-zlib.x86_64 : Tcl extension for zlib support jzlib-javadoc.noarch : API documentation for jzlib erlang-ezlib.x86_64 : Native zlib driver for Erlang jzlib.noarch : Re-implementation of zlib in pure Java tcl-zlib-devel.i686 : Development files for tcl-zlib tcl-zlib-devel.x86_64 : Development files for tcl-zlib zlib-ada-devel.x86_64 : Development files for Zlib-Ada zlibrary-devel.i686 : Development files for zlibrary zlibrary-devel.x86_64 : Development files for zlibrary zlib-static.i686 : Static libraries for Zlib development zlib-static.x86_64 : Static libraries for Zlib development smack-compression-jzlib.noarch : Smack compression with jzlib ghc-zlib-devel.x86_64 : Haskell zlib library development files ghc-zlib-enum.x86_64 : Enumerator interface for zlib compression perl-IO-Zlib.noarch : Perl IO:: style interface to Compress::Zlib ghc-zlib-bindings.x86_64 : Low-level bindings to the zlib package zlib-devel.i686 : Header files and libraries for Zlib development zlib-devel.x86_64 : Header files and libraries for Zlib development libknet1-compress-zlib-plugin.x86_64 : Provides libknet1 zlib support perl-POE-Filter-Zlib.noarch : POE filter wrapped around Compress::Zlib ghc-zlib-enum-devel.x86_64 : Haskell zlib-enum library development files mingw64-zlib-static.noarch : Static libraries for mingw64-zlib development mingw32-zlib-static.noarch : Static libraries for mingw32-zlib development. ghc-zlib.x86_64 : Compression and decompression in the gzip and zlib formats ghc-zlib-bindings-devel.x86_64 : Haskell zlib-bindings library development files nodejs-zlib-browserify.noarch : Wrapper for zlib.js to allow for use in browsers mingw32-zlib.noarch : MinGW Windows zlib compression library for the win32 : target mingw64-zlib.noarch : MinGW Windows zlib compression library for the win64 : target perl-Compress-Raw-Zlib.x86_64 : Low-level interface to the zlib compression : library perl-Compress-Raw-Zlib.x86_64 : Low-level interface to the zlib compression : library perl-Archive-Extract-Z-Compress-Zlib.noarch : Z decompressor for ...: perl-Archive-Extract via Compress::Zlib perl-Archive-Extract-gz-Compress-Zlib.noarch : Gzip decompressor for ...: perl-Archive-Extract via Compress::Zlib perl-Archive-Extract-tgz-Archive-Tar-IO-Zlib.noarch : Gzipped-tar decompressor ...: for perl-Archive-Extract via Archive::Tar and IO::Zlib perl-Archive-Extract-tgz-Archive-Tar-Compress-Zlib.noarch : Gzipped-tar ...: decompressor for perl-Archive-Extract via Archive::Tar and ...: Compress::Zlib =============================== 名前 一致: zlib ================================ js-zlib.noarch : JavaScript library reimplementing compression zlibrary.i686 : Cross-platform GUI library zlibrary.x86_64 : Cross-platform GUI library genwqe-zlib.i686 : GenWQE hardware accelerated libz genwqe-zlib.x86_64 : GenWQE hardware accelerated libz nodejs-zlibjs.noarch : JavaScript library reimplementing compression, made : available for Node.js genwqe-zlib-devel.i686 : Development files for genwqe-tools genwqe-zlib-devel.x86_64 : Development files for genwqe-tools genwqe-zlib-static.i686 : Static library files for genwqe-tools genwqe-zlib-static.x86_64 : Static library files for genwqe-tools =============================== 概要 一致: zlib ================================ zopfli.i686 : Zlib compatible better compressor zopfli.x86_64 : Zlib compatible better compressor python2-gzipstream.noarch : Streaming zlib (gzip) support for python python3-gzipstream.noarch : Streaming zlib (gzip) support for python miniz.i686 : Compression library implementing the zlib and Deflate miniz.x86_64 : Compression library implementing the zlib and Deflate rust-libz-sys-devel.noarch : Bindings to the system libz library (also known as : zlib) mingw32-gtk-vnc.noarch : MinGW Windows zlib compression library for the win32 : target mingw32-libidn.noarch : MinGW Windows zlib compression library for the win32 : target mingw64-gtk-vnc.noarch : MinGW Windows zlib compression library for the win64 : target mingw64-libidn.noarch : MinGW Windows zlib compression library for the win64 : target $
いろいろあるけど、zlibとzlib-develかな・・・。
$ sudo yum install zlib zlib-devel [sudo] bg1 のパスワード: メタデータの期限切れの最終確認: 0:05:53 時間前の 2019年xx月xx日 xx時xx分xx秒 に実施しました。 パッケージ zlib-1.2.11-14.fc29.x86_64 は既にインストールされています。 パッケージ zlib-devel-1.2.11-14.fc29.x86_64 は既にインストールされています。 依存関係が解決しました。 行うべきことはありません。 完了しました! $
既に入ってた・・・。
出力バッファと入力バッファの情報をz_streamに渡して、読んで変換して書き込みを繰り返す。
$ vi main.c $ ls jpeg_start_compress.c.txt main.c $ gcc main.c -o main -lz $ ls jpeg_start_compress.c.txt main main.c $ ls -al 合計 40 drwxrwxr-x. 2 bg1 bg1 4096 xx月 xx xx:xx . drwxrwxr-x. 3 bg1 bg1 4096 xx月 xx xx:xx .. -rw-rw-r--. 1 bg1 bg1 4197 xx月 xx xx:xx jpeg_start_compress.c.txt -rwxrwxr-x. 1 bg1 bg1 18616 xx月 xx xx:xx main -rw-rw-r--. 1 bg1 bg1 3861 xx月 xx xx:xx main.c $ ./main $ ls -al 合計 44 drwxrwxr-x. 2 bg1 bg1 4096 xx月 xx xx:xx . drwxrwxr-x. 3 bg1 bg1 4096 xx月 xx xx:xx .. -rw-rw-r--. 1 bg1 bg1 4197 xx月 xx xx:xx jpeg_start_compress.c.txt -rw-rw-r--. 1 bg1 bg1 1573 xx月 xx xx:xx jpeg_start_compress.c.z -rwxrwxr-x. 1 bg1 bg1 18616 xx月 xx xx:xx main -rw-rw-r--. 1 bg1 bg1 3861 xx月 xx xx:xx main.c $ cat jpeg_start_compress.c.z x��WmO��_�� /���>��T�$ݡ�R_Z5j��G����sQJdKI��)*I1͜%l]�n}w��˘�5����Ǔ�O0�8�֨��������P]�����j�Tߤj FliV�nL<� �m�����6��ѿL�G8Xb�,d..J�����m 50�?e&QR��#/&#C�aa��ɦ�Z�:� �b�5 ߐ����̽i1U��js=T�0������(�PT�RB!l��D>W��b1fM&D)��h�l<�0wju}�X�--���c��L���^J�*՟B���'��89��B<���m��?ƪn.LSu�je�M5^���T�P}���U��6��r29�Ez�,B��x2�{nS���ںH;�� 7�Ru���M�]�{����2�K���= ���q���\y[4�1��)���z �EV�a������^ $g&Hk�*l�I����.��:U���P���[��M?87Q���� UoqXH�T� HV9��P���m��*0+Va�M�d��~<��1E�nǒ�J�s���[1���v�4au�P��8�<@P�cI(��� ��m�eg��m���XU�L����"�3�i���s��fJ�x1O ��bR�@/-�e�XF�'�,����7c���\���f1�QZ�6�|�y�� �-���1��x��BV������ZP�ѩx)�� ���b�/>kg�9��d��5^�;���YQ��[y���������`���ܩ�(������Q-���fnG��G4�#H9A�:��Pנ���`�J(yj8���1Ww�6�y��\<��'�E�O!� ��w>�@�숛� w�C������F�'!qY�KY�c/&&�x�F�3�dM��Ÿ������n]*/�0��[��I�{���x]�<�=�: D7�l� r&�&���-�>ؙ:ة�����w�E�>z+�i�'��p5����7t�`%_�ح� �Fۑ���X�s�.�0���{�Q���]�Ň+�� g�j��vO[�t��(8�[���K�I���A�с�y�����݉ ��8�^��T]77����a��X���1�Q8���xڮ�"����Ĉ��v/�H��|�VX���9�%mĹy2�4�����q�4�DI,f�y��lYpb��+/�k�� Ȃv��z ¬[ޚ�9�8�� �: �A��=$��٘���� ��w'�z����D6_�͗�d��u������p� �������u�AZ���w+�h���ж�q�²�X! JI�@�B���X�$ $
libjpegで書いたjpeg_start_compress.cに".txt"拡張子を付けたファイルを圧縮して、4197byteが1573byteになった・・・。
まあ、正しく圧縮されてるかはわからんが・・・。
Sample/zlib/deflate/deflate/src/deflate at master · bg1bgst333/Sample · GitHub