From 319fab5061bb39ddf68cef7d70abb160bf5f03e3 Mon Sep 17 00:00:00 2001 From: Paul Marquess Date: Sat, 14 Mar 2009 00:45:02 +0000 Subject: Create IO-Compress --- MANIFEST | 271 ++-- ext/Compress-Raw-Bzip2/Changes | 2 +- ext/Compress-Raw-Bzip2/README | 8 +- ext/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm | 10 +- ext/Compress-Raw-Bzip2/pod/FAQ.pod | 2 +- ext/Compress-Raw-Bzip2/t/000prereq.t | 2 +- ext/Compress-Raw-Zlib/Changes | 10 + ext/Compress-Raw-Zlib/README | 39 +- ext/Compress-Raw-Zlib/Zlib.xs | 56 +- ext/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm | 226 ++- ext/Compress-Raw-Zlib/pod/FAQ.pod | 2 +- ext/Compress-Raw-Zlib/t/02zlib.t | 19 +- ext/Compress-Zlib/Changes | 507 ------- ext/Compress-Zlib/Makefile.PL | 81 -- ext/Compress-Zlib/README | 120 -- ext/Compress-Zlib/examples/filtdef | 29 - ext/Compress-Zlib/examples/filtinf | 28 - ext/Compress-Zlib/examples/gzcat | 27 - ext/Compress-Zlib/examples/gzgrep | 27 - ext/Compress-Zlib/examples/gzstream | 19 - ext/Compress-Zlib/lib/Compress/Zlib.pm | 1451 ------------------- ext/Compress-Zlib/pod/FAQ.pod | 125 -- ext/Compress-Zlib/private/MakeUtil.pm | 381 ----- ext/Compress-Zlib/t/01version.t | 42 - ext/Compress-Zlib/t/03zlib-v1.t | 1188 --------------- ext/Compress-Zlib/t/05examples.t | 163 --- ext/Compress-Zlib/t/06gzsetp.t | 139 -- ext/Compress-Zlib/t/08encoding.t | 139 -- ext/Compress-Zlib/t/14gzopen.t | 627 -------- ext/IO-Compress/Changes | 794 ++++++++++ ext/IO-Compress/MANIFEST | 151 ++ ext/IO-Compress/Makefile.PL | 47 + ext/IO-Compress/README | 94 ++ ext/IO-Compress/examples/compress-zlib/filtdef | 29 + ext/IO-Compress/examples/compress-zlib/filtinf | 28 + ext/IO-Compress/examples/compress-zlib/gzcat | 27 + ext/IO-Compress/examples/compress-zlib/gzgrep | 27 + ext/IO-Compress/examples/compress-zlib/gzstream | 19 + ext/IO-Compress/examples/io/anycat | 17 + ext/IO-Compress/examples/io/bzip2/bzcat | 29 + ext/IO-Compress/examples/io/bzip2/bzgrep | 25 + ext/IO-Compress/examples/io/bzip2/bzstream | 9 + ext/IO-Compress/examples/io/gzip/gzappend | 24 + ext/IO-Compress/examples/io/gzip/gzcat | 29 + ext/IO-Compress/examples/io/gzip/gzgrep | 40 + ext/IO-Compress/examples/io/gzip/gzstream | 24 + ext/IO-Compress/lib/Compress/Zlib.pm | 1456 +++++++++++++++++++ ext/IO-Compress/lib/File/GlobMapper.pm | 679 +++++++++ ext/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm | 162 +++ ext/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm | 165 +++ .../lib/IO/Compress/Adapter/Identity.pm | 101 ++ ext/IO-Compress/lib/IO/Compress/Base.pm | 981 +++++++++++++ ext/IO-Compress/lib/IO/Compress/Base/Common.pm | 940 ++++++++++++ ext/IO-Compress/lib/IO/Compress/Bzip2.pm | 758 ++++++++++ ext/IO-Compress/lib/IO/Compress/Deflate.pm | 889 ++++++++++++ ext/IO-Compress/lib/IO/Compress/Gzip.pm | 1201 +++++++++++++++ ext/IO-Compress/lib/IO/Compress/Gzip/Constants.pm | 148 ++ ext/IO-Compress/lib/IO/Compress/RawDeflate.pm | 976 +++++++++++++ ext/IO-Compress/lib/IO/Compress/Zip.pm | 1526 ++++++++++++++++++++ ext/IO-Compress/lib/IO/Compress/Zip/Constants.pm | 103 ++ ext/IO-Compress/lib/IO/Compress/Zlib/Constants.pm | 77 + ext/IO-Compress/lib/IO/Compress/Zlib/Extra.pm | 198 +++ .../lib/IO/Uncompress/Adapter/Bunzip2.pm | 199 +++ .../lib/IO/Uncompress/Adapter/Identity.pm | 102 ++ .../lib/IO/Uncompress/Adapter/Inflate.pm | 157 ++ ext/IO-Compress/lib/IO/Uncompress/AnyInflate.pm | 946 ++++++++++++ ext/IO-Compress/lib/IO/Uncompress/AnyUncompress.pm | 943 ++++++++++++ ext/IO-Compress/lib/IO/Uncompress/Base.pm | 1466 +++++++++++++++++++ ext/IO-Compress/lib/IO/Uncompress/Bunzip2.pm | 858 +++++++++++ ext/IO-Compress/lib/IO/Uncompress/Gunzip.pm | 1070 ++++++++++++++ ext/IO-Compress/lib/IO/Uncompress/Inflate.pm | 941 ++++++++++++ ext/IO-Compress/lib/IO/Uncompress/RawInflate.pm | 1069 ++++++++++++++ ext/IO-Compress/lib/IO/Uncompress/Unzip.pm | 1462 +++++++++++++++++++ ext/IO-Compress/pod/FAQ.pod | 512 +++++++ ext/IO-Compress/private/MakeUtil.pm | 381 +++++ ext/IO-Compress/t/000prereq.t | 56 + ext/IO-Compress/t/001bzip2.t | 206 +++ ext/IO-Compress/t/001zlib-generic-deflate.t | 20 + ext/IO-Compress/t/001zlib-generic-gzip.t | 20 + ext/IO-Compress/t/001zlib-generic-rawdeflate.t | 20 + ext/IO-Compress/t/001zlib-generic-zip.t | 20 + ext/IO-Compress/t/002any-deflate.t | 29 + ext/IO-Compress/t/002any-gzip.t | 29 + ext/IO-Compress/t/002any-rawdeflate.t | 28 + ext/IO-Compress/t/002any-transparent.t | 72 + ext/IO-Compress/t/002any-zip.t | 29 + ext/IO-Compress/t/004gziphdr.t | 962 ++++++++++++ ext/IO-Compress/t/005defhdr.t | 349 +++++ ext/IO-Compress/t/006zip.t | 276 ++++ ext/IO-Compress/t/010examples-bzip2.t | 145 ++ ext/IO-Compress/t/010examples-zlib.t | 145 ++ ext/IO-Compress/t/01misc.t | 281 ++++ ext/IO-Compress/t/020isize.t | 158 ++ ext/IO-Compress/t/050interop-gzip.t | 143 ++ ext/IO-Compress/t/100generic-bzip2.t | 21 + ext/IO-Compress/t/100generic-deflate.t | 22 + ext/IO-Compress/t/100generic-gzip.t | 21 + ext/IO-Compress/t/100generic-rawdeflate.t | 21 + ext/IO-Compress/t/100generic-zip.t | 21 + ext/IO-Compress/t/101truncate-bzip2.t | 37 + ext/IO-Compress/t/101truncate-deflate.t | 37 + ext/IO-Compress/t/101truncate-gzip.t | 36 + ext/IO-Compress/t/101truncate-rawdeflate.t | 130 ++ ext/IO-Compress/t/101truncate-zip.t | 38 + ext/IO-Compress/t/102tied-bzip2.t | 21 + ext/IO-Compress/t/102tied-deflate.t | 21 + ext/IO-Compress/t/102tied-gzip.t | 21 + ext/IO-Compress/t/102tied-rawdeflate.t | 21 + ext/IO-Compress/t/102tied-zip.t | 21 + ext/IO-Compress/t/103newtied-bzip2.t | 21 + ext/IO-Compress/t/103newtied-deflate.t | 21 + ext/IO-Compress/t/103newtied-gzip.t | 21 + ext/IO-Compress/t/103newtied-rawdeflate.t | 21 + ext/IO-Compress/t/103newtied-zip.t | 21 + ext/IO-Compress/t/104destroy-bzip2.t | 21 + ext/IO-Compress/t/104destroy-deflate.t | 21 + ext/IO-Compress/t/104destroy-gzip.t | 21 + ext/IO-Compress/t/104destroy-rawdeflate.t | 21 + ext/IO-Compress/t/104destroy-zip.t | 21 + ext/IO-Compress/t/105oneshot-bzip2.t | 22 + ext/IO-Compress/t/105oneshot-deflate.t | 21 + ext/IO-Compress/t/105oneshot-gzip-only.t | 134 ++ ext/IO-Compress/t/105oneshot-gzip.t | 22 + ext/IO-Compress/t/105oneshot-rawdeflate.t | 21 + ext/IO-Compress/t/105oneshot-zip-bzip2-only.t | 168 +++ ext/IO-Compress/t/105oneshot-zip-only.t | 237 +++ ext/IO-Compress/t/105oneshot-zip.t | 21 + ext/IO-Compress/t/106prime-bzip2.t | 21 + ext/IO-Compress/t/106prime-deflate.t | 21 + ext/IO-Compress/t/106prime-gzip.t | 21 + ext/IO-Compress/t/106prime-rawdeflate.t | 21 + ext/IO-Compress/t/106prime-zip.t | 21 + ext/IO-Compress/t/107multi-bzip2.t | 21 + ext/IO-Compress/t/107multi-deflate.t | 21 + ext/IO-Compress/t/107multi-gzip.t | 21 + ext/IO-Compress/t/107multi-rawdeflate.t | 21 + ext/IO-Compress/t/107multi-zip.t | 21 + ext/IO-Compress/t/108anyunc-bzip2.t | 29 + ext/IO-Compress/t/108anyunc-deflate.t | 29 + ext/IO-Compress/t/108anyunc-gzip.t | 29 + ext/IO-Compress/t/108anyunc-rawdeflate.t | 29 + ext/IO-Compress/t/108anyunc-transparent.t | 72 + ext/IO-Compress/t/108anyunc-zip.t | 29 + ext/IO-Compress/t/109merge-deflate.t | 21 + ext/IO-Compress/t/109merge-gzip.t | 21 + ext/IO-Compress/t/109merge-rawdeflate.t | 21 + ext/IO-Compress/t/109merge-zip.t | 24 + ext/IO-Compress/t/110encode-bzip2.t | 21 + ext/IO-Compress/t/110encode-deflate.t | 21 + ext/IO-Compress/t/110encode-gzip.t | 21 + ext/IO-Compress/t/110encode-rawdeflate.t | 21 + ext/IO-Compress/t/110encode-zip.t | 21 + ext/IO-Compress/t/999pod.t | 16 + ext/IO-Compress/t/99pod.t | 16 + ext/IO-Compress/t/cz-01version.t | 42 + ext/IO-Compress/t/cz-05examples.t | 163 +++ ext/IO-Compress/t/cz-06gzsetp.t | 139 ++ ext/IO-Compress/t/cz-08encoding.t | 139 ++ ext/IO-Compress/t/cz-14gzopen.t | 646 +++++++++ ext/IO-Compress/t/cz-99pod.t | 16 + ext/IO-Compress/t/globmapper.t | 304 ++++ ext/IO_Compress_Base/Changes | 194 --- ext/IO_Compress_Base/Makefile.PL | 53 - ext/IO_Compress_Base/README | 90 -- ext/IO_Compress_Base/lib/File/GlobMapper.pm | 679 --------- ext/IO_Compress_Base/lib/IO/Compress/Base.pm | 979 ------------- .../lib/IO/Compress/Base/Common.pm | 940 ------------ .../lib/IO/Uncompress/AnyUncompress.pm | 922 ------------ ext/IO_Compress_Base/lib/IO/Uncompress/Base.pm | 1456 ------------------- ext/IO_Compress_Base/pod/FAQ.pod | 346 ----- ext/IO_Compress_Base/private/MakeUtil.pm | 381 ----- ext/IO_Compress_Base/t/01misc.t | 281 ---- ext/IO_Compress_Base/t/globmapper.t | 304 ---- ext/IO_Compress_Zlib/Changes | 194 --- ext/IO_Compress_Zlib/Makefile.PL | 67 - ext/IO_Compress_Zlib/README | 107 -- ext/IO_Compress_Zlib/examples/gzappend | 24 - ext/IO_Compress_Zlib/examples/gzcat | 29 - ext/IO_Compress_Zlib/examples/gzgrep | 40 - ext/IO_Compress_Zlib/examples/gzstream | 24 - ext/IO_Compress_Zlib/examples/unzip | 73 - .../lib/IO/Compress/Adapter/Deflate.pm | 165 --- .../lib/IO/Compress/Adapter/Identity.pm | 101 -- ext/IO_Compress_Zlib/lib/IO/Compress/Deflate.pm | 889 ------------ ext/IO_Compress_Zlib/lib/IO/Compress/Gzip.pm | 1201 --------------- .../lib/IO/Compress/Gzip/Constants.pm | 148 -- ext/IO_Compress_Zlib/lib/IO/Compress/RawDeflate.pm | 976 ------------- ext/IO_Compress_Zlib/lib/IO/Compress/Zip.pm | 1512 ------------------- .../lib/IO/Compress/Zip/Constants.pm | 103 -- .../lib/IO/Compress/Zlib/Constants.pm | 77 - ext/IO_Compress_Zlib/lib/IO/Compress/Zlib/Extra.pm | 198 --- .../lib/IO/Uncompress/Adapter/Identity.pm | 102 -- .../lib/IO/Uncompress/Adapter/Inflate.pm | 161 --- .../lib/IO/Uncompress/AnyInflate.pm | 946 ------------ ext/IO_Compress_Zlib/lib/IO/Uncompress/Gunzip.pm | 1070 -------------- ext/IO_Compress_Zlib/lib/IO/Uncompress/Inflate.pm | 941 ------------ .../lib/IO/Uncompress/RawInflate.pm | 1052 -------------- ext/IO_Compress_Zlib/lib/IO/Uncompress/Unzip.pm | 1485 ------------------- ext/IO_Compress_Zlib/pod/FAQ.pod | 506 ------- ext/IO_Compress_Zlib/private/MakeUtil.pm | 381 ----- ext/IO_Compress_Zlib/t/001zlib-generic-deflate.t | 20 - ext/IO_Compress_Zlib/t/001zlib-generic-gzip.t | 20 - .../t/001zlib-generic-rawdeflate.t | 20 - ext/IO_Compress_Zlib/t/001zlib-generic-zip.t | 20 - ext/IO_Compress_Zlib/t/002any-deflate.t | 29 - ext/IO_Compress_Zlib/t/002any-gzip.t | 29 - ext/IO_Compress_Zlib/t/002any-rawdeflate.t | 28 - ext/IO_Compress_Zlib/t/002any-transparent.t | 72 - ext/IO_Compress_Zlib/t/002any-zip.t | 29 - ext/IO_Compress_Zlib/t/004gziphdr.t | 962 ------------ ext/IO_Compress_Zlib/t/005defhdr.t | 349 ----- ext/IO_Compress_Zlib/t/006zip.t | 276 ---- ext/IO_Compress_Zlib/t/010examples.t | 145 -- ext/IO_Compress_Zlib/t/020isize.t | 158 -- ext/IO_Compress_Zlib/t/050interop-gzip.t | 143 -- ext/IO_Compress_Zlib/t/100generic-deflate.t | 22 - ext/IO_Compress_Zlib/t/100generic-gzip.t | 21 - ext/IO_Compress_Zlib/t/100generic-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/100generic-zip.t | 21 - ext/IO_Compress_Zlib/t/101truncate-deflate.t | 37 - ext/IO_Compress_Zlib/t/101truncate-gzip.t | 36 - ext/IO_Compress_Zlib/t/101truncate-rawdeflate.t | 130 -- ext/IO_Compress_Zlib/t/101truncate-zip.t | 38 - ext/IO_Compress_Zlib/t/102tied-deflate.t | 21 - ext/IO_Compress_Zlib/t/102tied-gzip.t | 21 - ext/IO_Compress_Zlib/t/102tied-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/102tied-zip.t | 21 - ext/IO_Compress_Zlib/t/103newtied-deflate.t | 21 - ext/IO_Compress_Zlib/t/103newtied-gzip.t | 21 - ext/IO_Compress_Zlib/t/103newtied-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/103newtied-zip.t | 21 - ext/IO_Compress_Zlib/t/104destroy-deflate.t | 21 - ext/IO_Compress_Zlib/t/104destroy-gzip.t | 21 - ext/IO_Compress_Zlib/t/104destroy-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/104destroy-zip.t | 21 - ext/IO_Compress_Zlib/t/105oneshot-deflate.t | 21 - ext/IO_Compress_Zlib/t/105oneshot-gzip-only.t | 134 -- ext/IO_Compress_Zlib/t/105oneshot-gzip.t | 21 - ext/IO_Compress_Zlib/t/105oneshot-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/105oneshot-zip-only.t | 237 --- ext/IO_Compress_Zlib/t/105oneshot-zip.t | 21 - ext/IO_Compress_Zlib/t/106prime-deflate.t | 21 - ext/IO_Compress_Zlib/t/106prime-gzip.t | 21 - ext/IO_Compress_Zlib/t/106prime-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/106prime-zip.t | 21 - ext/IO_Compress_Zlib/t/107multi-deflate.t | 21 - ext/IO_Compress_Zlib/t/107multi-gzip.t | 21 - ext/IO_Compress_Zlib/t/107multi-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/107multi-zip.t | 21 - ext/IO_Compress_Zlib/t/108anyunc-deflate.t | 29 - ext/IO_Compress_Zlib/t/108anyunc-gzip.t | 29 - ext/IO_Compress_Zlib/t/108anyunc-rawdeflate.t | 29 - ext/IO_Compress_Zlib/t/108anyunc-transparent.t | 72 - ext/IO_Compress_Zlib/t/108anyunc-zip.t | 29 - ext/IO_Compress_Zlib/t/109merge-deflate.t | 21 - ext/IO_Compress_Zlib/t/109merge-gzip.t | 21 - ext/IO_Compress_Zlib/t/109merge-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/109merge-zip.t | 24 - ext/IO_Compress_Zlib/t/110encode-deflate.t | 21 - ext/IO_Compress_Zlib/t/110encode-gzip.t | 21 - ext/IO_Compress_Zlib/t/110encode-rawdeflate.t | 21 - ext/IO_Compress_Zlib/t/110encode-zip.t | 21 - t/lib/compress/generic.pl | 26 +- t/lib/compress/merge.pl | 4 +- t/lib/compress/multi.pl | 48 +- t/lib/compress/oneshot.pl | 34 +- 266 files changed, 28895 insertions(+), 28326 deletions(-) delete mode 100644 ext/Compress-Zlib/Changes delete mode 100755 ext/Compress-Zlib/Makefile.PL delete mode 100644 ext/Compress-Zlib/README delete mode 100755 ext/Compress-Zlib/examples/filtdef delete mode 100755 ext/Compress-Zlib/examples/filtinf delete mode 100755 ext/Compress-Zlib/examples/gzcat delete mode 100755 ext/Compress-Zlib/examples/gzgrep delete mode 100755 ext/Compress-Zlib/examples/gzstream delete mode 100644 ext/Compress-Zlib/lib/Compress/Zlib.pm delete mode 100644 ext/Compress-Zlib/pod/FAQ.pod delete mode 100644 ext/Compress-Zlib/private/MakeUtil.pm delete mode 100644 ext/Compress-Zlib/t/01version.t delete mode 100644 ext/Compress-Zlib/t/03zlib-v1.t delete mode 100644 ext/Compress-Zlib/t/05examples.t delete mode 100644 ext/Compress-Zlib/t/06gzsetp.t delete mode 100644 ext/Compress-Zlib/t/08encoding.t delete mode 100644 ext/Compress-Zlib/t/14gzopen.t create mode 100644 ext/IO-Compress/Changes create mode 100644 ext/IO-Compress/MANIFEST create mode 100644 ext/IO-Compress/Makefile.PL create mode 100644 ext/IO-Compress/README create mode 100755 ext/IO-Compress/examples/compress-zlib/filtdef create mode 100755 ext/IO-Compress/examples/compress-zlib/filtinf create mode 100755 ext/IO-Compress/examples/compress-zlib/gzcat create mode 100755 ext/IO-Compress/examples/compress-zlib/gzgrep create mode 100755 ext/IO-Compress/examples/compress-zlib/gzstream create mode 100755 ext/IO-Compress/examples/io/anycat create mode 100755 ext/IO-Compress/examples/io/bzip2/bzcat create mode 100755 ext/IO-Compress/examples/io/bzip2/bzgrep create mode 100755 ext/IO-Compress/examples/io/bzip2/bzstream create mode 100644 ext/IO-Compress/examples/io/gzip/gzappend create mode 100755 ext/IO-Compress/examples/io/gzip/gzcat create mode 100755 ext/IO-Compress/examples/io/gzip/gzgrep create mode 100755 ext/IO-Compress/examples/io/gzip/gzstream create mode 100644 ext/IO-Compress/lib/Compress/Zlib.pm create mode 100644 ext/IO-Compress/lib/File/GlobMapper.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Adapter/Identity.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Base.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Base/Common.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Bzip2.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Deflate.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Gzip.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Gzip/Constants.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/RawDeflate.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Zip.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Zip/Constants.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Zlib/Constants.pm create mode 100644 ext/IO-Compress/lib/IO/Compress/Zlib/Extra.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/Adapter/Bunzip2.pm create mode 100755 ext/IO-Compress/lib/IO/Uncompress/Adapter/Identity.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/Adapter/Inflate.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/AnyInflate.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/AnyUncompress.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/Base.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/Bunzip2.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/Gunzip.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/Inflate.pm create mode 100755 ext/IO-Compress/lib/IO/Uncompress/RawInflate.pm create mode 100644 ext/IO-Compress/lib/IO/Uncompress/Unzip.pm create mode 100644 ext/IO-Compress/pod/FAQ.pod create mode 100644 ext/IO-Compress/private/MakeUtil.pm create mode 100644 ext/IO-Compress/t/000prereq.t create mode 100644 ext/IO-Compress/t/001bzip2.t create mode 100644 ext/IO-Compress/t/001zlib-generic-deflate.t create mode 100644 ext/IO-Compress/t/001zlib-generic-gzip.t create mode 100644 ext/IO-Compress/t/001zlib-generic-rawdeflate.t create mode 100644 ext/IO-Compress/t/001zlib-generic-zip.t create mode 100644 ext/IO-Compress/t/002any-deflate.t create mode 100644 ext/IO-Compress/t/002any-gzip.t create mode 100644 ext/IO-Compress/t/002any-rawdeflate.t create mode 100644 ext/IO-Compress/t/002any-transparent.t create mode 100644 ext/IO-Compress/t/002any-zip.t create mode 100644 ext/IO-Compress/t/004gziphdr.t create mode 100644 ext/IO-Compress/t/005defhdr.t create mode 100644 ext/IO-Compress/t/006zip.t create mode 100644 ext/IO-Compress/t/010examples-bzip2.t create mode 100644 ext/IO-Compress/t/010examples-zlib.t create mode 100644 ext/IO-Compress/t/01misc.t create mode 100644 ext/IO-Compress/t/020isize.t create mode 100644 ext/IO-Compress/t/050interop-gzip.t create mode 100644 ext/IO-Compress/t/100generic-bzip2.t create mode 100644 ext/IO-Compress/t/100generic-deflate.t create mode 100644 ext/IO-Compress/t/100generic-gzip.t create mode 100644 ext/IO-Compress/t/100generic-rawdeflate.t create mode 100644 ext/IO-Compress/t/100generic-zip.t create mode 100644 ext/IO-Compress/t/101truncate-bzip2.t create mode 100644 ext/IO-Compress/t/101truncate-deflate.t create mode 100644 ext/IO-Compress/t/101truncate-gzip.t create mode 100644 ext/IO-Compress/t/101truncate-rawdeflate.t create mode 100644 ext/IO-Compress/t/101truncate-zip.t create mode 100644 ext/IO-Compress/t/102tied-bzip2.t create mode 100644 ext/IO-Compress/t/102tied-deflate.t create mode 100644 ext/IO-Compress/t/102tied-gzip.t create mode 100644 ext/IO-Compress/t/102tied-rawdeflate.t create mode 100644 ext/IO-Compress/t/102tied-zip.t create mode 100644 ext/IO-Compress/t/103newtied-bzip2.t create mode 100644 ext/IO-Compress/t/103newtied-deflate.t create mode 100644 ext/IO-Compress/t/103newtied-gzip.t create mode 100644 ext/IO-Compress/t/103newtied-rawdeflate.t create mode 100644 ext/IO-Compress/t/103newtied-zip.t create mode 100644 ext/IO-Compress/t/104destroy-bzip2.t create mode 100644 ext/IO-Compress/t/104destroy-deflate.t create mode 100644 ext/IO-Compress/t/104destroy-gzip.t create mode 100644 ext/IO-Compress/t/104destroy-rawdeflate.t create mode 100644 ext/IO-Compress/t/104destroy-zip.t create mode 100644 ext/IO-Compress/t/105oneshot-bzip2.t create mode 100644 ext/IO-Compress/t/105oneshot-deflate.t create mode 100644 ext/IO-Compress/t/105oneshot-gzip-only.t create mode 100644 ext/IO-Compress/t/105oneshot-gzip.t create mode 100644 ext/IO-Compress/t/105oneshot-rawdeflate.t create mode 100644 ext/IO-Compress/t/105oneshot-zip-bzip2-only.t create mode 100644 ext/IO-Compress/t/105oneshot-zip-only.t create mode 100644 ext/IO-Compress/t/105oneshot-zip.t create mode 100644 ext/IO-Compress/t/106prime-bzip2.t create mode 100644 ext/IO-Compress/t/106prime-deflate.t create mode 100644 ext/IO-Compress/t/106prime-gzip.t create mode 100644 ext/IO-Compress/t/106prime-rawdeflate.t create mode 100644 ext/IO-Compress/t/106prime-zip.t create mode 100644 ext/IO-Compress/t/107multi-bzip2.t create mode 100644 ext/IO-Compress/t/107multi-deflate.t create mode 100644 ext/IO-Compress/t/107multi-gzip.t create mode 100644 ext/IO-Compress/t/107multi-rawdeflate.t create mode 100644 ext/IO-Compress/t/107multi-zip.t create mode 100644 ext/IO-Compress/t/108anyunc-bzip2.t create mode 100644 ext/IO-Compress/t/108anyunc-deflate.t create mode 100644 ext/IO-Compress/t/108anyunc-gzip.t create mode 100644 ext/IO-Compress/t/108anyunc-rawdeflate.t create mode 100644 ext/IO-Compress/t/108anyunc-transparent.t create mode 100644 ext/IO-Compress/t/108anyunc-zip.t create mode 100644 ext/IO-Compress/t/109merge-deflate.t create mode 100644 ext/IO-Compress/t/109merge-gzip.t create mode 100644 ext/IO-Compress/t/109merge-rawdeflate.t create mode 100644 ext/IO-Compress/t/109merge-zip.t create mode 100644 ext/IO-Compress/t/110encode-bzip2.t create mode 100644 ext/IO-Compress/t/110encode-deflate.t create mode 100644 ext/IO-Compress/t/110encode-gzip.t create mode 100644 ext/IO-Compress/t/110encode-rawdeflate.t create mode 100644 ext/IO-Compress/t/110encode-zip.t create mode 100644 ext/IO-Compress/t/999pod.t create mode 100644 ext/IO-Compress/t/99pod.t create mode 100644 ext/IO-Compress/t/cz-01version.t create mode 100644 ext/IO-Compress/t/cz-05examples.t create mode 100644 ext/IO-Compress/t/cz-06gzsetp.t create mode 100644 ext/IO-Compress/t/cz-08encoding.t create mode 100644 ext/IO-Compress/t/cz-14gzopen.t create mode 100644 ext/IO-Compress/t/cz-99pod.t create mode 100644 ext/IO-Compress/t/globmapper.t delete mode 100644 ext/IO_Compress_Base/Changes delete mode 100644 ext/IO_Compress_Base/Makefile.PL delete mode 100644 ext/IO_Compress_Base/README delete mode 100644 ext/IO_Compress_Base/lib/File/GlobMapper.pm delete mode 100644 ext/IO_Compress_Base/lib/IO/Compress/Base.pm delete mode 100644 ext/IO_Compress_Base/lib/IO/Compress/Base/Common.pm delete mode 100644 ext/IO_Compress_Base/lib/IO/Uncompress/AnyUncompress.pm delete mode 100644 ext/IO_Compress_Base/lib/IO/Uncompress/Base.pm delete mode 100644 ext/IO_Compress_Base/pod/FAQ.pod delete mode 100644 ext/IO_Compress_Base/private/MakeUtil.pm delete mode 100644 ext/IO_Compress_Base/t/01misc.t delete mode 100644 ext/IO_Compress_Base/t/globmapper.t delete mode 100644 ext/IO_Compress_Zlib/Changes delete mode 100644 ext/IO_Compress_Zlib/Makefile.PL delete mode 100644 ext/IO_Compress_Zlib/README delete mode 100644 ext/IO_Compress_Zlib/examples/gzappend delete mode 100755 ext/IO_Compress_Zlib/examples/gzcat delete mode 100755 ext/IO_Compress_Zlib/examples/gzgrep delete mode 100755 ext/IO_Compress_Zlib/examples/gzstream delete mode 100644 ext/IO_Compress_Zlib/examples/unzip delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Adapter/Deflate.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Adapter/Identity.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Deflate.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Gzip.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Gzip/Constants.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/RawDeflate.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Zip.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Zip/Constants.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Zlib/Constants.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Compress/Zlib/Extra.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Uncompress/Adapter/Identity.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Uncompress/Adapter/Inflate.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Uncompress/AnyInflate.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Uncompress/Gunzip.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Uncompress/Inflate.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Uncompress/RawInflate.pm delete mode 100644 ext/IO_Compress_Zlib/lib/IO/Uncompress/Unzip.pm delete mode 100644 ext/IO_Compress_Zlib/pod/FAQ.pod delete mode 100644 ext/IO_Compress_Zlib/private/MakeUtil.pm delete mode 100644 ext/IO_Compress_Zlib/t/001zlib-generic-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/001zlib-generic-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/001zlib-generic-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/001zlib-generic-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/002any-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/002any-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/002any-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/002any-transparent.t delete mode 100644 ext/IO_Compress_Zlib/t/002any-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/004gziphdr.t delete mode 100644 ext/IO_Compress_Zlib/t/005defhdr.t delete mode 100644 ext/IO_Compress_Zlib/t/006zip.t delete mode 100644 ext/IO_Compress_Zlib/t/010examples.t delete mode 100644 ext/IO_Compress_Zlib/t/020isize.t delete mode 100644 ext/IO_Compress_Zlib/t/050interop-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/100generic-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/100generic-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/100generic-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/100generic-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/101truncate-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/101truncate-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/101truncate-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/101truncate-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/102tied-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/102tied-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/102tied-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/102tied-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/103newtied-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/103newtied-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/103newtied-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/103newtied-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/104destroy-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/104destroy-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/104destroy-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/104destroy-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/105oneshot-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/105oneshot-gzip-only.t delete mode 100644 ext/IO_Compress_Zlib/t/105oneshot-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/105oneshot-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/105oneshot-zip-only.t delete mode 100644 ext/IO_Compress_Zlib/t/105oneshot-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/106prime-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/106prime-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/106prime-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/106prime-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/107multi-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/107multi-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/107multi-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/107multi-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/108anyunc-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/108anyunc-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/108anyunc-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/108anyunc-transparent.t delete mode 100644 ext/IO_Compress_Zlib/t/108anyunc-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/109merge-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/109merge-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/109merge-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/109merge-zip.t delete mode 100644 ext/IO_Compress_Zlib/t/110encode-deflate.t delete mode 100644 ext/IO_Compress_Zlib/t/110encode-gzip.t delete mode 100644 ext/IO_Compress_Zlib/t/110encode-rawdeflate.t delete mode 100644 ext/IO_Compress_Zlib/t/110encode-zip.t diff --git a/MANIFEST b/MANIFEST index 4ff81a5a55..1427ba45e4 100644 --- a/MANIFEST +++ b/MANIFEST @@ -200,23 +200,6 @@ ext/Compress-Raw-Zlib/zlib-src/zlib.h Compress::Raw::Zlib ext/Compress-Raw-Zlib/zlib-src/zutil.c Compress::Raw::Zlib ext/Compress-Raw-Zlib/zlib-src/zutil.h Compress::Raw::Zlib ext/Compress-Raw-Zlib/Zlib.xs Compress::Raw::Zlib -ext/Compress-Zlib/Changes Compress::Zlib -ext/Compress-Zlib/examples/filtdef Compress::Zlib -ext/Compress-Zlib/examples/filtinf Compress::Zlib -ext/Compress-Zlib/examples/gzcat Compress::Zlib -ext/Compress-Zlib/examples/gzgrep Compress::Zlib -ext/Compress-Zlib/examples/gzstream Compress::Zlib -ext/Compress-Zlib/lib/Compress/Zlib.pm Compress::Zlib -ext/Compress-Zlib/Makefile.PL Compress::Zlib -ext/Compress-Zlib/pod/FAQ.pod Compress::Zlib -ext/Compress-Zlib/private/MakeUtil.pm Compress::Zlib -ext/Compress-Zlib/README Compress::Zlib -ext/Compress-Zlib/t/01version.t Compress::Zlib -ext/Compress-Zlib/t/03zlib-v1.t Compress::Zlib -ext/Compress-Zlib/t/05examples.t Compress::Zlib -ext/Compress-Zlib/t/06gzsetp.t Compress::Zlib -ext/Compress-Zlib/t/08encoding.t Compress::Zlib -ext/Compress-Zlib/t/14gzopen.t Compress::Zlib ext/Cwd/Changes Cwd extension Changelog ext/Cwd/Cwd.xs Cwd extension external subroutines ext/Cwd/Makefile.PL Cwd extension makefile maker @@ -754,107 +737,6 @@ ext/I18N-Langinfo/Langinfo.xs I18N::Langinfo ext/I18N-Langinfo/Makefile.PL I18N::Langinfo ext/I18N-Langinfo/t/Langinfo.t See whether I18N::Langinfo works ext/IO/ChangeLog IO perl module change log -ext/IO_Compress_Base/Changes IO::Compress::Base -ext/IO_Compress_Base/lib/File/GlobMapper.pm IO::Compress::Base -ext/IO_Compress_Base/lib/IO/Compress/Base/Common.pm IO::Compress::Base -ext/IO_Compress_Base/lib/IO/Compress/Base.pm IO::Compress::Base -ext/IO_Compress_Base/lib/IO/Uncompress/AnyUncompress.pm IO::Compress::Base -ext/IO_Compress_Base/lib/IO/Uncompress/Base.pm IO::Compress::Base -ext/IO_Compress_Base/Makefile.PL IO::Compress::Base -ext/IO_Compress_Base/pod/FAQ.pod IO::Compress::Base -ext/IO_Compress_Base/private/MakeUtil.pm IO::Compress::Base -ext/IO_Compress_Base/README IO::Compress::Base -ext/IO_Compress_Base/t/01misc.t IO::Compress::Base -ext/IO_Compress_Base/t/globmapper.t IO::Compress::Base -ext/IO_Compress_Zlib/Changes IO::Compress::Zlib -ext/IO_Compress_Zlib/examples/gzappend IO::Compress::Zlib -ext/IO_Compress_Zlib/examples/gzcat IO::Compress::Zlib -ext/IO_Compress_Zlib/examples/gzgrep IO::Compress::Zlib -ext/IO_Compress_Zlib/examples/gzstream IO::Compress::Zlib -ext/IO_Compress_Zlib/examples/unzip IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Adapter/Deflate.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Adapter/Identity.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Deflate.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Gzip/Constants.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Gzip.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/RawDeflate.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Zip/Constants.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Zip.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Zlib/Constants.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Compress/Zlib/Extra.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Uncompress/Adapter/Identity.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Uncompress/Adapter/Inflate.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Uncompress/AnyInflate.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Uncompress/Gunzip.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Uncompress/Inflate.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Uncompress/RawInflate.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/lib/IO/Uncompress/Unzip.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/Makefile.PL IO::Compress::Zlib -ext/IO_Compress_Zlib/pod/FAQ.pod IO::Compress::Zlib -ext/IO_Compress_Zlib/private/MakeUtil.pm IO::Compress::Zlib -ext/IO_Compress_Zlib/README IO::Compress::Zlib -ext/IO_Compress_Zlib/t/001zlib-generic-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/001zlib-generic-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/001zlib-generic-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/001zlib-generic-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/002any-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/002any-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/002any-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/002any-transparent.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/002any-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/004gziphdr.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/005defhdr.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/006zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/010examples.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/020isize.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/050interop-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/100generic-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/100generic-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/100generic-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/100generic-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/101truncate-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/101truncate-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/101truncate-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/101truncate-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/102tied-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/102tied-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/102tied-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/102tied-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/103newtied-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/103newtied-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/103newtied-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/103newtied-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/104destroy-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/104destroy-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/104destroy-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/104destroy-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/105oneshot-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/105oneshot-gzip-only.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/105oneshot-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/105oneshot-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/105oneshot-zip-only.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/105oneshot-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/106prime-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/106prime-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/106prime-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/106prime-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/107multi-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/107multi-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/107multi-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/107multi-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/108anyunc-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/108anyunc-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/108anyunc-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/108anyunc-transparent.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/108anyunc-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/109merge-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/109merge-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/109merge-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/109merge-zip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/110encode-deflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/110encode-gzip.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/110encode-rawdeflate.t IO::Compress::Zlib -ext/IO_Compress_Zlib/t/110encode-zip.t IO::Compress::Zlib ext/IO/hints/sco.pl Hint for IO for named architecture ext/IO/IO.pm Top-level interface to IO::* classes ext/IO/IO.xs IO extension external subroutines @@ -889,6 +771,159 @@ ext/IO/t/io_udp.t See if UDP socket-related methods from IO work ext/IO/t/io_unix.t See if UNIX socket-related methods from IO work ext/IO/t/io_utf8.t See if perlio opens work ext/IO/t/io_xs.t See if XSUB methods from IO work +ext/IO-Compress/ IO::Compress +ext/IO-Compress/t IO::Compress +ext/IO-Compress/t/004gziphdr.t IO::Compress +ext/IO-Compress/t/000prereq.t IO::Compress +ext/IO-Compress/t/109merge-gzip.t IO::Compress +ext/IO-Compress/t/109merge-deflate.t IO::Compress +ext/IO-Compress/t/001zlib-generic-deflate.t IO::Compress +ext/IO-Compress/t/103newtied-bzip2.t IO::Compress +ext/IO-Compress/t/108anyunc-transparent.t IO::Compress +ext/IO-Compress/t/107multi-gzip.t IO::Compress +ext/IO-Compress/t/100generic-bzip2.t IO::Compress +ext/IO-Compress/t/105oneshot-deflate.t IO::Compress +ext/IO-Compress/t/106prime-zip.t IO::Compress +ext/IO-Compress/t/101truncate-zip.t IO::Compress +ext/IO-Compress/t/105oneshot-gzip.t IO::Compress +ext/IO-Compress/t/106prime-rawdeflate.t IO::Compress +ext/IO-Compress/t/105oneshot-rawdeflate.t IO::Compress +ext/IO-Compress/t/01misc.t IO::Compress +ext/IO-Compress/t/cz-06gzsetp.t IO::Compress +ext/IO-Compress/t/001zlib-generic-gzip.t IO::Compress +ext/IO-Compress/t/110encode-deflate.t IO::Compress +ext/IO-Compress/t/001zlib-generic-zip.t IO::Compress +ext/IO-Compress/t/105oneshot-gzip-only.t IO::Compress +ext/IO-Compress/t/cz-05examples.t IO::Compress +ext/IO-Compress/t/999pod.t IO::Compress +ext/IO-Compress/t/101truncate-deflate.t IO::Compress +ext/IO-Compress/t/100generic-deflate.t IO::Compress +ext/IO-Compress/t/110encode-bzip2.t IO::Compress +ext/IO-Compress/t/001bzip2.t IO::Compress +ext/IO-Compress/t/006zip.t IO::Compress +ext/IO-Compress/t/108anyunc-bzip2.t IO::Compress +ext/IO-Compress/t/103newtied-zip.t IO::Compress +ext/IO-Compress/t/005defhdr.t IO::Compress +ext/IO-Compress/t/050interop-gzip.t IO::Compress +ext/IO-Compress/t/globmapper.t IO::Compress +ext/IO-Compress/t/110encode-zip.t IO::Compress +ext/IO-Compress/t/cz-08encoding.t IO::Compress +ext/IO-Compress/t/020isize.t IO::Compress +ext/IO-Compress/t/109merge-rawdeflate.t IO::Compress +ext/IO-Compress/t/108anyunc-gzip.t IO::Compress +ext/IO-Compress/t/107multi-zip.t IO::Compress +ext/IO-Compress/t/106prime-gzip.t IO::Compress +ext/IO-Compress/t/99pod.t IO::Compress +ext/IO-Compress/t/002any-transparent.t IO::Compress +ext/IO-Compress/t/106prime-deflate.t IO::Compress +ext/IO-Compress/t/105oneshot-zip-bzip2-only.t IO::Compress +ext/IO-Compress/t/010examples-bzip2.t IO::Compress +ext/IO-Compress/t/101truncate-gzip.t IO::Compress +ext/IO-Compress/t/002any-rawdeflate.t IO::Compress +ext/IO-Compress/t/107multi-bzip2.t IO::Compress +ext/IO-Compress/t/103newtied-rawdeflate.t IO::Compress +ext/IO-Compress/t/110encode-rawdeflate.t IO::Compress +ext/IO-Compress/t/010examples-zlib.t IO::Compress +ext/IO-Compress/t/102tied-deflate.t IO::Compress +ext/IO-Compress/t/106prime-bzip2.t IO::Compress +ext/IO-Compress/t/102tied-bzip2.t IO::Compress +ext/IO-Compress/t/101truncate-bzip2.t IO::Compress +ext/IO-Compress/t/001zlib-generic-rawdeflate.t IO::Compress +ext/IO-Compress/t/102tied-rawdeflate.t IO::Compress +ext/IO-Compress/t/102tied-gzip.t IO::Compress +ext/IO-Compress/t/108anyunc-deflate.t IO::Compress +ext/IO-Compress/t/104destroy-gzip.t IO::Compress +ext/IO-Compress/t/108anyunc-zip.t IO::Compress +ext/IO-Compress/t/105oneshot-zip-only.t IO::Compress +ext/IO-Compress/t/100generic-rawdeflate.t IO::Compress +ext/IO-Compress/t/110encode-gzip.t IO::Compress +ext/IO-Compress/t/100generic-gzip.t IO::Compress +ext/IO-Compress/t/002any-deflate.t IO::Compress +ext/IO-Compress/t/107multi-deflate.t IO::Compress +ext/IO-Compress/t/101truncate-rawdeflate.t IO::Compress +ext/IO-Compress/t/105oneshot-zip.t IO::Compress +ext/IO-Compress/t/100generic-zip.t IO::Compress +ext/IO-Compress/t/103newtied-deflate.t IO::Compress +ext/IO-Compress/t/cz-14gzopen.t IO::Compress +ext/IO-Compress/t/002any-gzip.t IO::Compress +ext/IO-Compress/t/102tied-zip.t IO::Compress +ext/IO-Compress/t/cz-01version.t IO::Compress +ext/IO-Compress/t/109merge-zip.t IO::Compress +ext/IO-Compress/t/105oneshot-bzip2.t IO::Compress +ext/IO-Compress/t/104destroy-rawdeflate.t IO::Compress +ext/IO-Compress/t/104destroy-zip.t IO::Compress +ext/IO-Compress/t/104destroy-bzip2.t IO::Compress +ext/IO-Compress/t/108anyunc-rawdeflate.t IO::Compress +ext/IO-Compress/t/002any-zip.t IO::Compress +ext/IO-Compress/t/cz-99pod.t IO::Compress +ext/IO-Compress/t/104destroy-deflate.t IO::Compress +ext/IO-Compress/t/107multi-rawdeflate.t IO::Compress +ext/IO-Compress/t/103newtied-gzip.t IO::Compress +ext/IO-Compress/Changes IO::Compress +ext/IO-Compress/lib IO::Compress +ext/IO-Compress/lib/IO IO::Compress +ext/IO-Compress/lib/IO/Uncompress IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Base.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Inflate.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Unzip.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/AnyUncompress.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Adapter IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Adapter/Bunzip2.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Adapter/Identity.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Adapter/Inflate.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/AnyInflate.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/RawInflate.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Bunzip2.pm IO::Compress +ext/IO-Compress/lib/IO/Uncompress/Gunzip.pm IO::Compress +ext/IO-Compress/lib/IO/Compress IO::Compress +ext/IO-Compress/lib/IO/Compress/Zip IO::Compress +ext/IO-Compress/lib/IO/Compress/Zip/Constants.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/RawDeflate.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Bzip2.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Zlib IO::Compress +ext/IO-Compress/lib/IO/Compress/Zlib/Constants.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Zlib/Extra.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Adapter IO::Compress +ext/IO-Compress/lib/IO/Compress/Adapter/Identity.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Gzip.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Deflate.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Zip.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Gzip IO::Compress +ext/IO-Compress/lib/IO/Compress/Gzip/Constants.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Base.pm IO::Compress +ext/IO-Compress/lib/IO/Compress/Base IO::Compress +ext/IO-Compress/lib/IO/Compress/Base/Common.pm IO::Compress +ext/IO-Compress/lib/Compress IO::Compress +ext/IO-Compress/lib/Compress/Zlib.pm IO::Compress +ext/IO-Compress/lib/File IO::Compress +ext/IO-Compress/lib/File/GlobMapper.pm IO::Compress +ext/IO-Compress/examples IO::Compress +ext/IO-Compress/examples/io IO::Compress +ext/IO-Compress/examples/io/anycat IO::Compress +ext/IO-Compress/examples/io/bzip2 IO::Compress +ext/IO-Compress/examples/io/bzip2/bzcat IO::Compress +ext/IO-Compress/examples/io/bzip2/bzgrep IO::Compress +ext/IO-Compress/examples/io/bzip2/bzstream IO::Compress +ext/IO-Compress/examples/io/gzip IO::Compress +ext/IO-Compress/examples/io/gzip/gzstream IO::Compress +ext/IO-Compress/examples/io/gzip/gzcat IO::Compress +ext/IO-Compress/examples/io/gzip/gzgrep IO::Compress +ext/IO-Compress/examples/io/gzip/gzappend IO::Compress +ext/IO-Compress/examples/compress-zlib IO::Compress +ext/IO-Compress/examples/compress-zlib/gzstream IO::Compress +ext/IO-Compress/examples/compress-zlib/gzcat IO::Compress +ext/IO-Compress/examples/compress-zlib/filtdef IO::Compress +ext/IO-Compress/examples/compress-zlib/gzgrep IO::Compress +ext/IO-Compress/examples/compress-zlib/filtinf IO::Compress +ext/IO-Compress/pod IO::Compress +ext/IO-Compress/pod/FAQ.pod IO::Compress +ext/IO-Compress/README IO::Compress +ext/IO-Compress/private IO::Compress +ext/IO-Compress/private/MakeUtil.pm IO::Compress +ext/IO-Compress/Makefile.PL IO::Compress +ext/IO-Compress/MANIFEST IO::Compress ext/IPC-SysV/Changes IPC::SysV changes ext/IPC-SysV/hints/cygwin.pl Hint for IPC::SysV for named architecture ext/IPC-SysV/hints/next_3.pl Hint for IPC::SysV for named architecture diff --git a/ext/Compress-Raw-Bzip2/Changes b/ext/Compress-Raw-Bzip2/Changes index f25e57a017..f5133dbedd 100644 --- a/ext/Compress-Raw-Bzip2/Changes +++ b/ext/Compress-Raw-Bzip2/Changes @@ -1,7 +1,7 @@ CHANGES ------- - 2.016 26 February 2009 + 2.017 26 February 2009 * Minor changes to allow building in perl core. diff --git a/ext/Compress-Raw-Bzip2/README b/ext/Compress-Raw-Bzip2/README index 158b897002..d54c8596aa 100644 --- a/ext/Compress-Raw-Bzip2/README +++ b/ext/Compress-Raw-Bzip2/README @@ -1,11 +1,11 @@ Compress-Raw-Bzip2 - Version 2.015 + Version 2.017 - 2nd September 2008 + 28th February 2009 - Copyright (c) 2005-2008 Paul Marquess. All rights reserved. + Copyright (c) 2005-2009 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. @@ -159,7 +159,7 @@ To help me help you, I need all of the following information: If you haven't installed Compress-Raw-Bzip2 then search Compress::Raw::Bzip2.pm for a line like this: - $VERSION = "2.015" ; + $VERSION = "2.017" ; c. The version of bzip2 you have used. If you have successfully installed Compress-Raw-Bzip2, this one-liner diff --git a/ext/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm b/ext/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm index ebc60a05fb..3b4615276b 100644 --- a/ext/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm +++ b/ext/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm @@ -12,7 +12,7 @@ use Carp ; use bytes ; our ($VERSION, $XS_VERSION, @ISA, @EXPORT, $AUTOLOAD); -$VERSION = '2.015'; +$VERSION = '2.017'; $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -275,6 +275,12 @@ If C is enabled in the constructor for the bunzip2 object, the uncompressed data will be appended to C<$output>. If not enabled, C<$output> will be truncated before the uncompressed data is written to it. +=head1 Misc + +=head2 my $version = Compress::Raw::Bzip2::bzlibversion(); + +Returns the version of the underlying bzip2 library. + =head1 Constants The following bzip2 constants are exported by this module @@ -322,7 +328,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2008 Paul Marquess. All rights reserved. +Copyright (c) 2005-2009 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/ext/Compress-Raw-Bzip2/pod/FAQ.pod b/ext/Compress-Raw-Bzip2/pod/FAQ.pod index f429807958..41921a5d44 100644 --- a/ext/Compress-Raw-Bzip2/pod/FAQ.pod +++ b/ext/Compress-Raw-Bzip2/pod/FAQ.pod @@ -112,7 +112,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2008 Paul Marquess. All rights reserved. +Copyright (c) 2005-2009 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/ext/Compress-Raw-Bzip2/t/000prereq.t b/ext/Compress-Raw-Bzip2/t/000prereq.t index 99d249be55..1467eeda7d 100644 --- a/ext/Compress-Raw-Bzip2/t/000prereq.t +++ b/ext/Compress-Raw-Bzip2/t/000prereq.t @@ -19,7 +19,7 @@ BEGIN if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - my $VERSION = '2.015'; + my $VERSION = '2.016'; my @NAMES = qw( ); diff --git a/ext/Compress-Raw-Zlib/Changes b/ext/Compress-Raw-Zlib/Changes index e818e4f2f7..c66156cb5c 100644 --- a/ext/Compress-Raw-Zlib/Changes +++ b/ext/Compress-Raw-Zlib/Changes @@ -1,6 +1,16 @@ CHANGES ------- + 2.017 1 February 2009 + + * Added 'LimitOutput' option + TODO - document it + + * Documented Compress::Raw::Zlib::zlib_version() + + * Documented Compress::Raw::Zlib::deflateReset() + [RT #40566] + 2.015 3 September 2008 * Makefile.PL diff --git a/ext/Compress-Raw-Zlib/README b/ext/Compress-Raw-Zlib/README index 0a5f5182cc..1a35da425f 100644 --- a/ext/Compress-Raw-Zlib/README +++ b/ext/Compress-Raw-Zlib/README @@ -1,11 +1,11 @@ Compress-Raw-Zlib - Version 2.015 + Version 2.017 - 2nd September 2008 + 28th February 2009 - Copyright (c) 2005-2008 Paul Marquess. All rights reserved. + Copyright (c) 2005-2009 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. @@ -177,6 +177,35 @@ this module. TROUBLESHOOTING --------------- +Undefined Symbol gzsetparams +---------------------------- + +If you get the error shown below when you run the Compress-Raw-Zlib test +harness it probably means you are running a copy of zlib that is +version 1.0.5 or older. + +t/01version.........Can't load 'blib/arch/auto/Compress/Zlib/Zlib.so' for + module Compress::Raw::Zlib: blib/arch/auto/Compress/Raw/Zlib/Zlib.so: + undefined symbol: gzsetparams at ... + +There are two ways to fix this problem: + + 1. Upgrade to the latest version of zlib. + + 2. Edit config.in and set the OLD_ZLIB variable to True. + +Test Harness 01version fails +---------------------------- +If the 01version test harness fails, and the problem isn't covered by the +scenario above, it probably means that you have two versions of +zlib installed on your system. + +Run the command below to see if this is indeed the case + + make test TEST_VERBOSE=1 TEST_FILES=t/01version.t + +Try removing the one you don't want to use and rebuild. + Solaris build fails with "language optional software package not installed" --------------------------------------------------------------------------- @@ -277,7 +306,7 @@ it ships with a pre-compiled version of Compress-Raw-Zlib. To check if a newer version of Compress-Raw-Zlib is available run this from the command prompt - C:\> ppm verify -upgrade Compress-Zlib + C:\> ppm verify -upgrade Compress-Raw-Zlib If you are not running Activestate Perl and you don't have access to a C compiler, you will not be able to build and install this module. @@ -326,7 +355,7 @@ To help me help you, I need all of the following information: If you haven't installed Compress-Raw-Zlib then search Compress::Raw::Zlib.pm for a line like this: - $VERSION = "2.015" ; + $VERSION = "2.017" ; c. The version of zlib you have used. If you have successfully installed Compress-Raw-Zlib, this one-liner diff --git a/ext/Compress-Raw-Zlib/Zlib.xs b/ext/Compress-Raw-Zlib/Zlib.xs index 821e1d1c7b..9a117f3a41 100644 --- a/ext/Compress-Raw-Zlib/Zlib.xs +++ b/ext/Compress-Raw-Zlib/Zlib.xs @@ -3,7 +3,7 @@ * Created : 22nd January 1996 * Version : 2.000 * - * Copyright (c) 1995-2007 Paul Marquess. All rights reserved. + * Copyright (c) 1995-2009 Paul Marquess. All rights reserved. * This program is free software; you can redistribute it and/or * modify it under the same terms as Perl itself. * @@ -1272,7 +1272,7 @@ inflate (s, buf, output, eof=FALSE) bool eof uInt cur_length = 0; uInt prefix_length = 0; - uInt increment = 0; + int increment = 0; STRLEN stmp = NO_INIT uLong bufinc = NO_INIT PREINIT: @@ -1306,21 +1306,37 @@ inflate (s, buf, output, eof=FALSE) if((s->flags & FLAG_APPEND) != FLAG_APPEND) { SvCUR_set(output, 0); } + + /* Assume no output buffer - the code below will update if there is any available */ + s->stream.avail_out = 0; + + if (SvLEN(output)) { prefix_length = cur_length = SvCUR(output) ; - s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length; - increment = SvLEN(output) - cur_length - 1; - s->stream.avail_out = increment; - } - else { - s->stream.avail_out = 0; + + if (s->flags & FLAG_LIMIT_OUTPUT && SvLEN(output) - cur_length - 1 < bufinc) + { + Sv_Grow(output, bufinc + cur_length + 1) ; + } + + /* Only setup the stream output pointers if there is spare + capacity in the outout SV + */ + if (SvLEN(output) > cur_length + 1) + { + s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length; + increment = SvLEN(output) - cur_length - 1; + s->stream.avail_out = increment; + } } + + s->bytesInflated = 0; RETVAL = Z_OK; while (RETVAL == Z_OK) { - if (s->stream.avail_out == 0 ) { + if (s->stream.avail_out == 0) { /* out of space in the output buffer so make it bigger */ Sv_Grow(output, SvLEN(output) + bufinc) ; cur_length += increment ; @@ -1330,7 +1346,13 @@ inflate (s, buf, output, eof=FALSE) bufinc *= 2 ; } + /* printf("INFLATE Availl In %d, Out %d\n", s->stream.avail_in, + s->stream.avail_out); +DispStream(s, "BEFORE"); +Perl_sv_dump(output); */ RETVAL = inflate(&(s->stream), Z_SYNC_FLUSH); + /* printf("INFLATE returned %d %s, avail in %d, out %d\n", RETVAL, + GetErrorString(RETVAL), s->stream.avail_in, s->stream.avail_out); */ if (RETVAL == Z_NEED_DICT && s->dictionary) { @@ -1338,11 +1360,16 @@ inflate (s, buf, output, eof=FALSE) RETVAL = inflateSetDictionary(&(s->stream), (const Bytef*)SvPVbyte_nolen(s->dictionary), SvCUR(s->dictionary)); + if (RETVAL == Z_OK) + continue; } - if (s->flags & FLAG_LIMIT_OUTPUT || - RETVAL == Z_STREAM_ERROR || RETVAL == Z_MEM_ERROR || - RETVAL == Z_DATA_ERROR || RETVAL == Z_STREAM_END ) + if (s->flags & FLAG_LIMIT_OUTPUT && + (RETVAL == Z_OK || RETVAL == Z_BUF_ERROR )) + break; + + if (RETVAL == Z_STREAM_ERROR || RETVAL == Z_MEM_ERROR || + RETVAL == Z_DATA_ERROR || RETVAL == Z_STREAM_END ) break ; if (RETVAL == Z_BUF_ERROR) { @@ -1376,8 +1403,8 @@ inflate (s, buf, output, eof=FALSE) #endif s->last_error = RETVAL ; - if (RETVAL == Z_OK || RETVAL == Z_STREAM_END || RETVAL == Z_DATA_ERROR) { - unsigned in ; + if (RETVAL == Z_OK || RETVAL == Z_STREAM_END || RETVAL == Z_BUF_ERROR || RETVAL == Z_DATA_ERROR) { + unsigned in ; s->bytesInflated = cur_length + increment - s->stream.avail_out - prefix_length; s->uncompressedBytes += s->bytesInflated ; @@ -1411,6 +1438,7 @@ inflate (s, buf, output, eof=FALSE) *SvEND(buf) = '\0'; SvSETMAGIC(buf); } + } OUTPUT: RETVAL diff --git a/ext/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm b/ext/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm index 6d096e016d..ee87bfa883 100644 --- a/ext/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm +++ b/ext/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm @@ -13,7 +13,7 @@ use warnings ; use bytes ; our ($VERSION, $XS_VERSION, @ISA, @EXPORT, $AUTOLOAD); -$VERSION = '2.015'; +$VERSION = '2.017'; $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -547,6 +547,7 @@ Compress::Raw::Zlib - Low-Level Interface to zlib compression library ($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ; $status = $d->deflate($input, $output) ; $status = $d->flush($output [, $flush_type]) ; + $d->deflateReset() ; $d->deflateParams(OPTS) ; $d->deflateTune(OPTS) ; $d->dict_adler() ; @@ -576,8 +577,7 @@ Compress::Raw::Zlib - Low-Level Interface to zlib compression library $crc = adler32_combine($crc1, $crc2, $len2)l $crc = crc32_combine($adler1, $adler2, $len2) - ZLIB_VERSION - ZLIB_VERNUM + my $version = Compress::Raw::Zlib::zlib_version(); =head1 DESCRIPTION @@ -763,6 +763,16 @@ the C<$d> object, the compressed data will be appended to C<$output>. If it is false, C<$output> will be truncated before any compressed data is written to it. +=head2 B<$status = $d-EdeflateReset() > + +This method will reset the deflation object C<$d>. It can be used when you +are compressing multiple data streams and want to use the same object to +compress each of them. It should only be used once the previous data stream +has been flushed successfully, i.e. a call to C<< $d->flush(Z_FINISH) >> has +returned C. + +Returns C if successful. + =head2 B<$status = $d-EdeflateParams([OPT])> Change settings for the deflate object C<$d>. @@ -965,7 +975,7 @@ This option defaults to false. =item B<-ConsumeInput> If set to true, this option will remove compressed data from the input -buffer of the the C< $i-Einflate > method as the inflate progresses. +buffer of the C<< $i->inflate >> method as the inflate progresses. This option can be useful when you are processing compressed data that is embedded in another file/buffer. In this case the data that immediately @@ -973,6 +983,162 @@ follows the compressed stream will be left in the input buffer. This option defaults to true. +=item B<-LimitOutput> + +The C option changes the behavior of the C<< $i->inflate >> +method so that the amount of memory used by the output buffer can be +limited. + +When C is used the size of the output buffer used will either +be the value of the C option or the amount of memory already +allocated to C<$output>, whichever is larger. Predicting the output size +available is tricky, so don't rely on getting an exact output buffer size. + +When C is not specified C<< $i->inflate >> will use as much +memory as it takes to write all the uncompressed data it creates by +uncompressing the input buffer. + +See ?? for a discussion on why C is needed and how to use it. + +If C is enabled, the C option will also be +enabled. + +The input buffer may not have been fully processed, so the C +option will enable C + +This option defaults to false. + +B + +By default C<< $i->inflate($input, $output) >> will uncompress I data +in C<$input> and write I of the uncompressed data it has generated to +C<$output>. This makes the interface to C much simpler - if the +method has uncompressed C<$input> successfully I compressed data in +C<$input> will have been dealt with. So if you are reading from an input +source and uncompressing as you go the code will look something like this + + use strict ; + use warnings ; + + use Compress::Raw::Zlib; + + my $x = new Compress::Raw::Zlib::Inflate() + or die "Cannot create a inflation stream\n" ; + + my $input = '' ; + + my ($output, $status) ; + while (read(STDIN, $input, 4096)) + { + $status = $x->inflate($input, $output) ; + + print $output ; + + last if $status != Z_OK ; + } + + die "inflation failed\n" + unless $status == Z_STREAM_END ; + +The points to note are + +=over 5 + +=item * + +C will only terminate the loop if it returns a status that isn't +C, i.e. the end of the compressed data stream has been reached or +there has been an error in uncompression. + +=item * + +After the call to C I of the uncompressed data in C<$input> +will have been processed. This means the subsequent call to C can +overwrite it's contents without any problem. + +=back + +For most use-cases the behavior described above is acceptable (this module +and it's predecessor, C, have used it for over 10 years +without an issue), but in a few very specific use-cases the amount of +memory required for C<$output> can prohibitively large. For example, if the +compressed data stream contains the same pattern repeated thousands of +times a relatively small compressed data stream can uncompress into hundreds +of megabytes. Remember C will keep allocating memory until all +the uncompressed data has been written to the output buffer - the size of +C<$output> is unbounded. + +If you need to cope with this use-case, C is for you. + +The main difference in your code when using C is having to +deal with cases where the C<$input> parameter still contains some +uncompressed data that C hasn't processed yet. Below is a typical +code + + use strict ; + use warnings ; + + use Compress::Raw::Zlib; + + my $x = new Compress::Raw::Zlib::Inflate(LimitOutput => 1) + or die "Cannot create a inflation stream\n" ; + + my $input = '' ; + binmode STDIN; + binmode STDOUT; + + my ($output, $status) ; + + OUTER: + while (read(STDIN, $input, 4096)) + { + do + { + $status = $x->inflate($input, $output) ; + + print $output ; + + last OUTER + unless $status == Z_OK || $status == Z_BUF_ERROR ; + } + while ($status == Z_OK && length $input); + } + + die "inflation failed\n" + unless $status == Z_STREAM_END ; + +Points to note this time: + +=over 5 + +=item * + +There are now two nested loops: the outer loop for reading the compressed +data from STDIN; and the inner loop to repeatedly uncompress the C<$input> +buffer. + +=item * + +There are two way the inner loop can be terminated + +=back + +If you know the underlying zlib interface, C will call the +zlib C function once + +Limiting the size of the output buffer means that there will be cases where +C<$input> will not have been completely processed. + +See L for an example of how to use C. + +it will return after a single call to the underlying +zlib C function. + +once the output buffer is full. + +As with the default it will also return if an error is encountered or the +end of the compressed data stream is reached. + =back Here is an example of using an optional parameter to override the default @@ -1101,7 +1267,7 @@ Returns the total number of uncompressed bytes output from inflate. Returns the buffer size used to carry out the decompression. -=head2 Example +=head2 Examples Here is an example of using C. @@ -1120,7 +1286,7 @@ Here is an example of using C. my ($output, $status) ; while (read(STDIN, $input, 4096)) { - $status = $x->inflate(\$input, $output) ; + $status = $x->inflate($input, $output) ; print $output if $status == Z_OK or $status == Z_STREAM_END ; @@ -1131,6 +1297,46 @@ Here is an example of using C. die "inflation failed\n" unless $status == Z_STREAM_END ; +The next example show how to use the C option. Notice the use +of two nested loops in this case. The outer loop reads the data from the +input source - STDIN and the inner loop repeatedly calls C until +C<$input> is exhausted, we get an error, or the end of the stream is +reached. One point worth remembering is by using the C option +you also get C set as well - this makes the code below much +simpler. + + use strict ; + use warnings ; + + use Compress::Raw::Zlib; + + my $x = new Compress::Raw::Zlib::Inflate(LimitOutput => 1) + or die "Cannot create a inflation stream\n" ; + + my $input = '' ; + binmode STDIN; + binmode STDOUT; + + my ($output, $status) ; + + OUTER: + while (read(STDIN, $input, 4096)) + { + do + { + $status = $x->inflate($input, $output) ; + + print $output ; + + last OUTER + unless $status == Z_OK || $status == Z_BUF_ERROR ; + } + while ($status == Z_OK && length $input); + } + + die "inflation failed\n" + unless $status == Z_STREAM_END ; + =head1 CHECKSUM FUNCTIONS Two functions are provided by I to calculate checksums. For the @@ -1153,6 +1359,12 @@ CRC-related functions are available. These functions allow checksums to be merged. +=head1 Misc + +=head2 my $version = Compress::Raw::Zlib::zlib_version(); + +Returns the version of the zlib library. + =head1 ACCESSING ZIP FILES Although it is possible (with some effort on your part) to use this @@ -1199,7 +1411,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2008 Paul Marquess. All rights reserved. +Copyright (c) 2005-2009 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/ext/Compress-Raw-Zlib/pod/FAQ.pod b/ext/Compress-Raw-Zlib/pod/FAQ.pod index 0a78bbbdf4..56d08f5cfe 100644 --- a/ext/Compress-Raw-Zlib/pod/FAQ.pod +++ b/ext/Compress-Raw-Zlib/pod/FAQ.pod @@ -135,7 +135,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2008 Paul Marquess. All rights reserved. +Copyright (c) 2005-2009 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/ext/Compress-Raw-Zlib/t/02zlib.t b/ext/Compress-Raw-Zlib/t/02zlib.t index 889566afd4..7d379249b5 100644 --- a/ext/Compress-Raw-Zlib/t/02zlib.t +++ b/ext/Compress-Raw-Zlib/t/02zlib.t @@ -24,13 +24,13 @@ BEGIN my $count = 0 ; if ($] < 5.005) { - $count = 229 ; + $count = 230 ; } elsif ($] >= 5.006) { - $count = 283 ; + $count = 284 ; } else { - $count = 241 ; + $count = 242 ; } plan tests => $count + $extra; @@ -443,10 +443,13 @@ for my $consume ( 0 .. 1) # create a flush point cmp_ok $x->flush($Answer, Z_FULL_FLUSH), '==', Z_OK ; + + my $len1 = length $Answer; cmp_ok $x->deflate($goodbye, $Answer), '==', Z_OK; cmp_ok $x->flush($Answer), '==', Z_OK ; + my $len2 = length($Answer) - $len1 ; my ($first, @Answer) = split('', $Answer) ; @@ -475,7 +478,6 @@ for my $consume ( 0 .. 1) $GOT .= $Z if defined $Z ; # print "x $status\n"; last if $status == Z_STREAM_END or $status != Z_OK ; - } cmp_ok $status, '==', Z_DATA_ERROR ; @@ -488,7 +490,7 @@ for my $consume ( 0 .. 1) my $initial = $1 ; - ok(($k, $err) = new Compress::Raw::Zlib::Inflate(-ConsumeInput => 0)) ; + ok(($k, $err) = new Compress::Raw::Zlib::Inflate(ConsumeInput => 0)) ; ok $k ; cmp_ok $err, '==', Z_OK ; @@ -499,8 +501,11 @@ for my $consume ( 0 .. 1) cmp_ok $status, '==', Z_OK or diag "status '$status'\nlength rest is " . length($rest) . "\n" ; - cmp_ok $k->inflate($rest, $GOT), '==', Z_DATA_ERROR; - is $Z . $GOT, $goodbye ; + is length($rest), $len2, "expected compressed output"; + + $GOT = ''; + cmp_ok $k->inflate($rest, $GOT), '==', Z_DATA_ERROR, "inflate returns Z_DATA_ERROR"; + is $GOT, $goodbye ; } { diff --git a/ext/Compress-Zlib/Changes b/ext/Compress-Zlib/Changes deleted file mode 100644 index 931eea6e94..0000000000 --- a/ext/Compress-Zlib/Changes +++ /dev/null @@ -1,507 +0,0 @@ -CHANGES -------- - - 2.015 3 September 2008 - - * Makefile.PL - Backout changes made in 2.014 - - 2.014 2 September 2008 - - * Makefile.PL - Updated to check for indirect dependencies. - - 2.012 15 July 2008 - - * No Changes - - 2.011 17 May 2008 - - * No Changes - - 2.010 5 May 2008 - - * Fixed problem that meant Perl 5.10 could not upgrade this module. - [RT #35341] - - 2.009 20 April 2008 - - * Minor documentation issue with flush. - [rt.cpan.org #31446] - - 2.008 2 November 2007 - - * Minor documentation changes in README - - 2.007 22 September 20007 - - * lib/Compress/Zlib.pm -- 1.x Backward Compatability issues - gzclose - documented return value was wrong, should be 0 for ok. - gzflush - return value didn't match 1.x, should return 0 if ok. - [rt.cpan.org #29215] and Debian bug #440943 http://bugs.debian.org/440943 - - 2.006 1 September 20007 - - * Makefile.PL - Added INSTALLDIRS directive to install as a core module when built - on a perl >= 5.9. - - * t/03zlib-v1.t - Fixed crc32 and adler32 tests in to remove ascii assumption. - - * lib/Compress/Zlib.pm - Make gzreadline not support $/, just like in Compress::Zlib 1.x - Folk who want $/ with readline support can get it in - IO::Uncompress::Gunzip. - [rt.cpan.org #28663] and Debian bug #435656 http://bugs.debian.org/435656 - 2.005 18 June 2007 - - * Added info about removing Compress::Zlib version 1, before - installing version 2. - - 2.004 3 March 2007 - - * rewrote memGzip using IO::Compress::Gzip::gzip - - 2.003 2 January 2007 - - * Added explicit version checking - - 2.002 29 December 2006 - - * Documentation updates. - - * Fix append mode with gzopen. - rt-cpan.org 24041 - - * Allow gzopen to read from and write to a scalar reference. - - 2.001 1 November 2006 - - * Remove beta status. - - 2.000_14 26 October 2006 - - * No changes. - - 2.000_13 20 June 2006 - - * No changes. - - 2.000_12 16 April 2006 - - * Fixed gzread to zap the output buffer to an empty string when zero - bytes are requested. This matches the behaviour of C::Z 1.x - - 2.000_11 10 April 2006 - - * No changes. - - 2.000_10 13 March 2006 - - * Changed gzread so that its behaviour matches C::Z::gzread 1.x if it - is called after eof. In this case it will write an empty string - into the output parameter. This change is solely for backward - compatability reasons. - - 2.000_09 3 March 2006 - - * Posted to CPAN - - 2.000_08 2 March 2006 - - * Breakout zlib specific code into separate modules. - - * Limited support for reading/writing zip files - - 2.000_06 5 October 2005 - - * Added eof parameter to Compress::Zlib::inflate method. - - * Fixed issue with 64-bit - - 2.000_05 4 October 2005 - - * Renamed IO::* to IO::Compress::* & IO::Uncompress::* - - 2.000_04 23 September 2005 - - * Fixed some more non-portable test that were failing on VMS. - - * fixed problem where error messages in the oneshot interface were - getting lost. - - 2.000_03 12 September 2005 - - * Fixed some non-portable test that were failing on VMS. - - * Fixed export of zlib constants from the IO::* classes - - 2.000_02 6 September 2005 - - * Split Append mode into Append and Merge - - * Fixed typos in the documentation. - - * Added pod/FAQ.pod - - * Added libscan to Makefile.PL - - * Added InputLength for IO::Gunzip et al - - 2.000_01 22 August 2005 - - * Fixed VERSION in Compress::Gzip::Constants - - * Removed Compress::Gzip::Info from the distribution. - - 2.000_00 21 August 2005 - - * First Beta relase of Compress::zlib rewrite. - - 1.38 - 6 September 2005 - - * Integrate core change 25304 -- Symbian Update - - * Added libscan to Makefile.PL - - 1.37 - 12 August 2005 - - * Change to t/03examples.t for VMS from Abe Timmerman - - 1.36 - 3 August 2005 - - * Renamed zlib-src-1.2.3 to zlib-src to help VMS - - * Fixed Makefile.PL for VMS - - * Fixed t/03examples.t for VMS - - * Added a couple of notes about incompatibility with Unix compress. - - 1.35 - 16 July 2005 - - * Updated zlib source to 1.2.3 - - * Fixed problem with where two calls to gzclose would hang the debugger. - See https://rt.cpan.org/Ticket/Display.html?id=13789 - - * Added code from Alexey Tourbin to use XSLoader when available, - and DynaLoader otherwise. - - * Documented that the compress & uncompress functions were not - the same as the Unix utilities of the same name. - - * Fixed 05gzsetp -- it left a temp file hanging around. - - * Integrate core change 24787 - SvUPGRADE returns void in blead - - * Integrate core change 24788 - Makefile.PL adjustments for the core - - - 1.34 - 30 January 2005 - - * Fixed typo in the README - - * Fixed examples.t on Win32 where paths have embedded whitespace. - - * Fix for Cygwin and core integration from Jos I. Boumans - - * Upgrade zlib source to 1.2.2 - - 1.33 - 14 January 2004 - - * Reworked Makefile.PL to avoid creating a private copy of zlib. - This both simplifies the build, plus it makes life easier for VMS. - - * Patches for Makefile.PL to get it to work on VMS supplied by - Craig A. Berry. - - * memGunzip has very slow on FreeBSD. Turns out to be down to - the way realloc works on FreeBSD. Changed both inflate & deflate - to use exponentially increasing buffer sizes when they need to - realloc. Thanks to Peter Jeremy for the lowdown on FreeBSD - memory allocation. - - 1.32 - 26 November 2003 - - * Steve Hay reported a problem on rt.cpan.org with Windows and - MSCV++ 6.0 where the source from the zlib directory was getting - installed with the rest of the module. - https://rt.cpan.org/Ticket/Display.html?id=1741 - - This has been fixed by renaming the "zlib" directory to "zlib-src" - thus avoiding a conflict with the name of this Perl module. - - * Fixed a bug in the inflate method where the input buffer is an - lvalue (via substr). Problem & solution reported by Salvador Fandiqo. - - * Tightened up the logic in Makefile.PL when BUILD_ZLIB is - True. Issue spotted by Ralf S. Engelschall. - - 1.31 - 29 October 2003 - - * Reinstated the creation of .bak files - $^I seems to need a - backup file on Windows. For OpenVMS, the extenstion _bak is used. - - 1.30 - 28 October 2003 - - * Bundled a sub-set of the zlib source with the module and changed - the default make behaviour to build with the included zlib source. - The previous behaviour of using a pre-built zlib library is - still available for those that want it. - - * Added prototypes to the subs in Zlib.pm that didn't already have - them. Patch from Ed Avis. - - * No .bak files are created by Makefile.PL any more - this keep - distclean much happier. Patch suggested by Ed Avis. - This also fixes a similar problem reported by Dr. Martin Zinser - on OpenVMS. - - * Documentation for some of the gz functions updated. - - * Format strings modified in DispStream to keep OpenVMS happy. - Problem reported by Dr. Martin Zinser. - - - 1.22 - 17 June 2003 - - * Makefile.PL now displays a warning about not installing - Compress::Zlib via the CPAN shell. - - * Fix to allow intermingling of gzread & gzreadline - patch - supplied by Doug Perham. - - * memGunzip will silently now work if the gzip trailer is - missing. Some HTTP Origin Servers seem to leave it out. - - 1.21 - 28 April 2003 - - * Tests 148 & 150 from t/02zlib.t were failing on redhat 9. - - * Added a few words about the problems with Mac OS X to the README file. - - 1.20 - 4 April 2003 - - * Fixed bug in gzopen where $gzerrno wasn't being set correctly. - The symptom was $gzerrno was set to Z_MEM_ERROR although the file - was opened ok. If gzopen failed, $gzerrno was being set correctly. - This problem wasn't spotted before because the typical test - to determine whether gzopen passed or failed was to check its - return value. - - 1.19 - 31 October 2002 - - * fixed a problem with t/02zlib.t that was failing with redhat 8. - - 1.18 - 24 October 2002 - - * fixed a Win32 problem in t/02zlib.t by changing sysread to read. - - * zlib 1.0.5 & older doesn't have gzsetparams & gzeof. Added a new - variable to config.in to flag an old version of zlib. Split - out the tests for gzsetparams into t/05gzsetp.t - - 1.17 - 23 May 2002 - - * Moved the test to check the versions of libz & zlib.h into a separate - file and added troubleshooting notes to README. - - * In gzopen, only attempt to call "tell" for normal files. - - * Fixed to work in taint mode. - - * Broke changes out of README into Changes file. - - * Replaced internal use of Z_PARTIAL_FLUSH symbol with Z_SYNC_FLUSH. - zlib.h says /* will be removed, use Z_SYNC_FLUSH instead */ - - 1.16 - 13 December 2001 - - * Fixed bug in Makefile.PL that stopped "perl Makefile.PL PREFIX=..." - working. - - 1.15 - 4th December 2001 - - * Changes a few types to get the module to build on 64-bit Solaris - - * Changed the up/downgrade logic to default to the older constructs, and - to only call a downgrade if specifically requested. Some older versions - of Perl were having problems with the in-place edit. - - * added the new XS constant code. - - 1.14 - 27th August 2001 - - * Memory overwrite bug fixed in "inflate". Kudos to Rob Simons for - reporting the bug and to Anton Berezin for fixing it for me. - - 1.13 - 31st June 2001 - - * Make sure config.in is consistant when released. - - 1.12 - 28th April 2001 - - * Modified Makefile.PL to only enable the warnings pragma if - using perl 5.6.1 or better. - - 1.11 - 17th February 2001 - - * Added logic in Makefile.PL to toggle between using $^W and - the warnings pragma in the module. - - * The module, the examples & the test harness are now all strict - & warnings clean. - - 1.10 - 5th February 2001 - - * fixed a bug in memGunzip. Used Z_ERR instead of Z_DATA_ERROR. - - 1.09 - 15th January 2001 - - * Silenced a few compiler warnings. - - * Updated zlib home site in README & Zlib.pm to www.info-zip.org - - * Minor typo in Zlib.pm - a link used AUTHORS instead of AUTHOR - -- spotted by Frank Martini. - - * Mention Archive::Zip - - * added memGunzip. This is largely based on code provided by Jim Leonard. - - * $deflate->flush can now take an optional parameter. Valid - values are Z_NO_FLUSH, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH - and Z_FINISH. The default is Z_FINISH. - - 1.08 - 6 Jan 2000 - - * uncompress was clobbering its input parameter. Now it doesn't. - This bug was spotted by Deven T. Corzine. - - * If a variable that only ever contained a number was given - to compress or deflate, it would not be compressed properly. Now - it will be coerced to a string and then compressed. This bug - was spotted by Deven T. Corzine. - - 1.07 - 27 Nov 1999 - - * ANSI-ified the static functions in Zlib.xs - - * Added the ability to build zlib along with the module. - This feature is 90% based on a Makefile provided by Gurusamy - Sarathy. - - 1.06 - 20 Sep 1999 - - * Fixed a nasty problem where inflate could truncate the data - returned. Thanks to Douglas Thomson - for both spotting the problem and fixing the bug. - - * Added a note about the undocumented features in zlib that are - required when accessing zip files. - - * gzclose will now get called automatically when the gzip object is - destroyed. - - 1.05 - 3 June 1999 - - * Previous release used newSVpvn, which doesn't exist in 5.004_04 - or earlier. Changed to use newSVpv instead. - - * The module needs Perl 5.004 or better, so updated the version - checking in Zlib.pm and Makefile.PL - - 1.04 - 27 May 1999 - - * Bug 19990527.001: compress(undef) core dumps -- Fixed. - - 1.03 - 17 Mar 1999 - - * Updated to use the new PL_ symbols. - Means the module can be built with Perl 5.005_5* - - 1.02 - 31 Jan 1999 - - * The return codes for gzread, gzreadline and gzwrite were - documented incorrectly as returning a status code. - - * The test harness was missing a "gzclose". This caused problem - showed up on an amiga. Thanks to Erik van Roode for reporting - this one. - - * Patched zlib.t for OS/2. Thanks to Ilya Zakharevich for the patch. - - 1.01 - 23 Nov 1997 - - * A number of fixes to the test suite and the example scripts to - allow them to work under win32. All courtesy of Gurusamy - Sarathy. - - 1.00 - 14 Nov 1997 - - * Fixed crc32 & adler32. They were very broken. - - * The following functions can now take a scalar reference in - place of a scalar for their buffer parameters: - - compress - uncompress - deflate - inflate - crc32 - adler32 - - This should mean applications that make use of the module don't - have to copy large buffers around. - - - * Normally the inflate method consumes I of the input buffer - before returning. The exception to this is when inflate detects - the end of the stream (Z_STREAM_END). In this case the input - buffer need not be completely consumed. To allow processing of - file formats that embed a deflation stream (e.g. zip, gzip), - the inflate method now sets the buffer parameter to be what - remains after inflation. - - When the return status is Z_STREAM_END, it will be what remains - of the buffer (if any) after deflation. When the status is Z_OK - it will be an empty string. - - This change means that the buffer parameter must be a lvalue. - - * Fixed crc32 and adler32. They were both very broken. - - * Added the Compress::Zlib::memGzip function. - - 0.5 - Confirmed that no changes were necessary for zlib 1.0.3, or 1.0.4. - - The optional parameters for deflateInit and inflateInit can now - be specified as an associative array in addition to a reference - to an associative array. They can also accept the -Name - syntax. - - gzopen can now optionally take a reference to an open - filehandle in place of a filename. In this case it will call - gzdopen. - - Added gzstream example script. - - 0.4 - Upgrade to support zlib 0.99 - - Added dictionary interface. - - Fixed bug in gzreadline - previously it would keep returning - the same buffer. This bug was reported by Helmut Jarausch - - Removed dependency to zutil.h and so dropped support for - - DEF_MEM_LEVEL (use MAX_MEM_LEVEL instead) - DEF_WBITS (use MAX_WBITS instead) - - 0.3 - Added prototype specification. - - 0.2 - Fixed a minor allocation problem in Zlib.xs - - 0.1 - first alpha release. 2nd October 1995 diff --git a/ext/Compress-Zlib/Makefile.PL b/ext/Compress-Zlib/Makefile.PL deleted file mode 100755 index 1f6ba8060a..0000000000 --- a/ext/Compress-Zlib/Makefile.PL +++ /dev/null @@ -1,81 +0,0 @@ -#! perl -w - -use strict ; -require 5.004 ; - -$::VERSION = '2.015' ; - -use private::MakeUtil; -use ExtUtils::MakeMaker 5.16 ; - - -UpDowngrade(getPerlFiles('MANIFEST')) - unless $ENV{PERL_CORE}; - -WriteMakefile( - NAME => 'Compress::Zlib', - VERSION_FROM => 'lib/Compress/Zlib.pm', - 'dist' => { COMPRESS => 'gzip', - TARFLAGS => '-chvf', - SUFFIX => 'gz', - DIST_DEFAULT => 'MyTrebleCheck tardist', - }, - - ( - $ENV{SKIP_FOR_CORE} - ? (MAN3PODS => {}) - : (PREREQ_PM => { 'Compress::Raw::Zlib' => $::VERSION, - 'IO::Compress::Base' => $::VERSION, - 'IO::Compress::Base::Common' => $::VERSION, - 'IO::Uncompress::Base' => $::VERSION, - 'IO::Compress::Gzip' => $::VERSION, - 'IO::Compress::Gzip::Constants' => $::VERSION, - 'IO::Uncompress::Gunzip' => $::VERSION, - 'Scalar::Util' => 0, - } - ) - ), - - ( - $] >= 5.005 - ? (ABSTRACT_FROM => 'lib/Compress/Zlib.pm', - AUTHOR => 'Paul Marquess ') - : () - ), - - INSTALLDIRS => ($] >= 5.009 ? 'perl' : 'site'), - - ( - $] >= 5.009 && ! $ENV{PERL_CORE} - ? (INST_LIB => 'blib/arch') - : () - ), - - ((ExtUtils::MakeMaker->VERSION() gt '6.30') ? - ('LICENSE' => 'perl') : ()), - -) ; - -# Check for Compress::Zlib version 1. -eval "require Compress::Zlib; " ; -if ( ! $ENV{PERL_CORE} && ! $@ && $Compress::Zlib::VERSION < 2) -{ - my $ver = $Compress::Zlib::VERSION ; - print < diff --git a/ext/Compress-Zlib/examples/filtdef b/ext/Compress-Zlib/examples/filtdef deleted file mode 100755 index 57dfeb9068..0000000000 --- a/ext/Compress-Zlib/examples/filtdef +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/local/bin/perl - -use strict ; -use warnings ; - -use Compress::Zlib ; - -binmode STDIN; -binmode STDOUT; -my $x = deflateInit() - or die "Cannot create a deflation stream\n" ; - -my ($output, $status) ; -while (<>) -{ - ($output, $status) = $x->deflate($_) ; - - $status == Z_OK - or die "deflation failed\n" ; - - print $output ; -} - -($output, $status) = $x->flush() ; - -$status == Z_OK - or die "deflation failed\n" ; - -print $output ; diff --git a/ext/Compress-Zlib/examples/filtinf b/ext/Compress-Zlib/examples/filtinf deleted file mode 100755 index 1df202b1d7..0000000000 --- a/ext/Compress-Zlib/examples/filtinf +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/local/bin/perl - -use strict ; -use warnings ; - -use Compress::Zlib ; - -my $x = inflateInit() - or die "Cannot create a inflation stream\n" ; - -my $input = '' ; -binmode STDIN; -binmode STDOUT; - -my ($output, $status) ; -while (read(STDIN, $input, 4096)) -{ - ($output, $status) = $x->inflate(\$input) ; - - print $output - if $status == Z_OK or $status == Z_STREAM_END ; - - last if $status != Z_OK ; -} - -die "inflation failed\n" - unless $status == Z_STREAM_END ; - diff --git a/ext/Compress-Zlib/examples/gzcat b/ext/Compress-Zlib/examples/gzcat deleted file mode 100755 index 5241a5a11f..0000000000 --- a/ext/Compress-Zlib/examples/gzcat +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/local/bin/perl - -use strict ; -use warnings ; - -use Compress::Zlib ; - -#die "Usage: gzcat file...\n" -# unless @ARGV ; - -my $filename ; - -@ARGV = '-' unless @ARGV ; - -foreach my $filename (@ARGV) { - my $buffer ; - - my $gz = gzopen($filename, "rb") - or die "Cannot open $filename: $gzerrno\n" ; - - print $buffer while $gz->gzread($buffer) > 0 ; - - die "Error reading from $filename: $gzerrno" . ($gzerrno+0) . "\n" - if $gzerrno != Z_STREAM_END ; - - $gz->gzclose() ; -} diff --git a/ext/Compress-Zlib/examples/gzgrep b/ext/Compress-Zlib/examples/gzgrep deleted file mode 100755 index 324d3e615f..0000000000 --- a/ext/Compress-Zlib/examples/gzgrep +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/local/bin/perl - -use strict ; -use warnings ; - -use Compress::Zlib ; - -die "Usage: gzgrep pattern file...\n" - unless @ARGV >= 2; - -my $pattern = shift ; - -my $file ; - -foreach $file (@ARGV) { - my $gz = gzopen($file, "rb") - or die "Cannot open $file: $gzerrno\n" ; - - while ($gz->gzreadline($_) > 0) { - print if /$pattern/ ; - } - - die "Error reading from $file: $gzerrno\n" - if $gzerrno != Z_STREAM_END ; - - $gz->gzclose() ; -} diff --git a/ext/Compress-Zlib/examples/gzstream b/ext/Compress-Zlib/examples/gzstream deleted file mode 100755 index faacb0a0dd..0000000000 --- a/ext/Compress-Zlib/examples/gzstream +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/local/bin/perl - -use strict ; -use warnings ; - -use Compress::Zlib ; - -binmode STDOUT; # gzopen only sets it on the fd - -#my $gz = gzopen(\*STDOUT, "wb") -my $gz = gzopen('-', "wb") - or die "Cannot open stdout: $gzerrno\n" ; - -while (<>) { - $gz->gzwrite($_) - or die "error writing: $gzerrno\n" ; -} - -$gz->gzclose ; diff --git a/ext/Compress-Zlib/lib/Compress/Zlib.pm b/ext/Compress-Zlib/lib/Compress/Zlib.pm deleted file mode 100644 index 7c712f6330..0000000000 --- a/ext/Compress-Zlib/lib/Compress/Zlib.pm +++ /dev/null @@ -1,1451 +0,0 @@ - -package Compress::Zlib; - -require 5.004 ; -require Exporter; -use AutoLoader; -use Carp ; -use IO::Handle ; -use Scalar::Util qw(dualvar); - -use IO::Compress::Base::Common 2.015 ; -use Compress::Raw::Zlib 2.015 ; -use IO::Compress::Gzip 2.015 ; -use IO::Uncompress::Gunzip 2.015 ; - -use strict ; -use warnings ; -use bytes ; -our ($VERSION, $XS_VERSION, @ISA, @EXPORT, $AUTOLOAD); - -$VERSION = '2.015'; -$XS_VERSION = $VERSION; -$VERSION = eval $VERSION; - -@ISA = qw(Exporter); -# Items to export into callers namespace by default. Note: do not export -# names by default without a very good reason. Use EXPORT_OK instead. -# Do not simply export all your public functions/methods/constants. -@EXPORT = qw( - deflateInit inflateInit - - compress uncompress - - gzopen $gzerrno - ); - -push @EXPORT, @Compress::Raw::Zlib::EXPORT ; - -BEGIN -{ - *zlib_version = \&Compress::Raw::Zlib::zlib_version; -} - -sub AUTOLOAD { - my($constname); - ($constname = $AUTOLOAD) =~ s/.*:://; - my ($error, $val) = Compress::Raw::Zlib::constant($constname); - Carp::croak $error if $error; - no strict 'refs'; - *{$AUTOLOAD} = sub { $val }; - goto &{$AUTOLOAD}; -} - -use constant FLAG_APPEND => 1 ; -use constant FLAG_CRC => 2 ; -use constant FLAG_ADLER => 4 ; -use constant FLAG_CONSUME_INPUT => 8 ; - -our (@my_z_errmsg); - -@my_z_errmsg = ( - "need dictionary", # Z_NEED_DICT 2 - "stream end", # Z_STREAM_END 1 - "", # Z_OK 0 - "file error", # Z_ERRNO (-1) - "stream error", # Z_STREAM_ERROR (-2) - "data error", # Z_DATA_ERROR (-3) - "insufficient memory", # Z_MEM_ERROR (-4) - "buffer error", # Z_BUF_ERROR (-5) - "incompatible version",# Z_VERSION_ERROR(-6) - ); - - -sub _set_gzerr -{ - my $value = shift ; - - if ($value == 0) { - $Compress::Zlib::gzerrno = 0 ; - } - elsif ($value == Z_ERRNO() || $value > 2) { - $Compress::Zlib::gzerrno = $! ; - } - else { - $Compress::Zlib::gzerrno = dualvar($value+0, $my_z_errmsg[2 - $value]); - } - - return $value ; -} - -sub _save_gzerr -{ - my $gz = shift ; - my $test_eof = shift ; - - my $value = $gz->errorNo() || 0 ; - - if ($test_eof) { - #my $gz = $self->[0] ; - # gzread uses Z_STREAM_END to denote a successful end - $value = Z_STREAM_END() if $gz->eof() && $value == 0 ; - } - - _set_gzerr($value) ; -} - -sub gzopen($$) -{ - my ($file, $mode) = @_ ; - - my $gz ; - my %defOpts = (Level => Z_DEFAULT_COMPRESSION(), - Strategy => Z_DEFAULT_STRATEGY(), - ); - - my $writing ; - $writing = ! ($mode =~ /r/i) ; - $writing = ($mode =~ /[wa]/i) ; - - $defOpts{Level} = $1 if $mode =~ /(\d)/; - $defOpts{Strategy} = Z_FILTERED() if $mode =~ /f/i; - $defOpts{Strategy} = Z_HUFFMAN_ONLY() if $mode =~ /h/i; - $defOpts{Append} = 1 if $mode =~ /a/i; - - my $infDef = $writing ? 'deflate' : 'inflate'; - my @params = () ; - - croak "gzopen: file parameter is not a filehandle or filename" - unless isaFilehandle $file || isaFilename $file || - (ref $file && ref $file eq 'SCALAR'); - - return undef unless $mode =~ /[rwa]/i ; - - _set_gzerr(0) ; - - if ($writing) { - $gz = new IO::Compress::Gzip($file, Minimal => 1, AutoClose => 1, - %defOpts) - or $Compress::Zlib::gzerrno = $IO::Compress::Gzip::GzipError; - } - else { - $gz = new IO::Uncompress::Gunzip($file, - Transparent => 1, - Append => 0, - AutoClose => 1, - MultiStream => 1, - Strict => 0) - or $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError; - } - - return undef - if ! defined $gz ; - - bless [$gz, $infDef], 'Compress::Zlib::gzFile'; -} - -sub Compress::Zlib::gzFile::gzread -{ - my $self = shift ; - - return _set_gzerr(Z_STREAM_ERROR()) - if $self->[1] ne 'inflate'; - - my $len = defined $_[1] ? $_[1] : 4096 ; - - if ($self->gzeof() || $len == 0) { - # Zap the output buffer to match ver 1 behaviour. - $_[0] = "" ; - return 0 ; - } - - my $gz = $self->[0] ; - my $status = $gz->read($_[0], $len) ; - _save_gzerr($gz, 1); - return $status ; -} - -sub Compress::Zlib::gzFile::gzreadline -{ - my $self = shift ; - - my $gz = $self->[0] ; - { - # Maintain backward compatibility with 1.x behaviour - # It didn't support $/, so this can't either. - local $/ = "\n" ; - $_[0] = $gz->getline() ; - } - _save_gzerr($gz, 1); - return defined $_[0] ? length $_[0] : 0 ; -} - -sub Compress::Zlib::gzFile::gzwrite -{ - my $self = shift ; - my $gz = $self->[0] ; - - return _set_gzerr(Z_STREAM_ERROR()) - if $self->[1] ne 'deflate'; - - $] >= 5.008 and (utf8::downgrade($_[0], 1) - or croak "Wide character in gzwrite"); - - my $status = $gz->write($_[0]) ; - _save_gzerr($gz); - return $status ; -} - -sub Compress::Zlib::gzFile::gztell -{ - my $self = shift ; - my $gz = $self->[0] ; - my $status = $gz->tell() ; - _save_gzerr($gz); - return $status ; -} - -sub Compress::Zlib::gzFile::gzseek -{ - my $self = shift ; - my $offset = shift ; - my $whence = shift ; - - my $gz = $self->[0] ; - my $status ; - eval { $status = $gz->seek($offset, $whence) ; }; - if ($@) - { - my $error = $@; - $error =~ s/^.*: /gzseek: /; - $error =~ s/ at .* line \d+\s*$//; - croak $error; - } - _save_gzerr($gz); - return $status ; -} - -sub Compress::Zlib::gzFile::gzflush -{ - my $self = shift ; - my $f = shift ; - - my $gz = $self->[0] ; - my $status = $gz->flush($f) ; - my $err = _save_gzerr($gz); - return $status ? 0 : $err; -} - -sub Compress::Zlib::gzFile::gzclose -{ - my $self = shift ; - my $gz = $self->[0] ; - - my $status = $gz->close() ; - my $err = _save_gzerr($gz); - return $status ? 0 : $err; -} - -sub Compress::Zlib::gzFile::gzeof -{ - my $self = shift ; - my $gz = $self->[0] ; - - return 0 - if $self->[1] ne 'inflate'; - - my $status = $gz->eof() ; - _save_gzerr($gz); - return $status ; -} - -sub Compress::Zlib::gzFile::gzsetparams -{ - my $self = shift ; - croak "Usage: Compress::Zlib::gzFile::gzsetparams(file, level, strategy)" - unless @_ eq 2 ; - - my $gz = $self->[0] ; - my $level = shift ; - my $strategy = shift; - - return _set_gzerr(Z_STREAM_ERROR()) - if $self->[1] ne 'deflate'; - - my $status = *$gz->{Compress}->deflateParams(-Level => $level, - -Strategy => $strategy); - _save_gzerr($gz); - return $status ; -} - -sub Compress::Zlib::gzFile::gzerror -{ - my $self = shift ; - my $gz = $self->[0] ; - - return $Compress::Zlib::gzerrno ; -} - - -sub compress($;$) -{ - my ($x, $output, $err, $in) =('', '', '', '') ; - - if (ref $_[0] ) { - $in = $_[0] ; - croak "not a scalar reference" unless ref $in eq 'SCALAR' ; - } - else { - $in = \$_[0] ; - } - - $] >= 5.008 and (utf8::downgrade($$in, 1) - or croak "Wide character in compress"); - - my $level = (@_ == 2 ? $_[1] : Z_DEFAULT_COMPRESSION() ); - - $x = new Compress::Raw::Zlib::Deflate -AppendOutput => 1, -Level => $level - or return undef ; - - $err = $x->deflate($in, $output) ; - return undef unless $err == Z_OK() ; - - $err = $x->flush($output) ; - return undef unless $err == Z_OK() ; - - return $output ; - -} - -sub uncompress($) -{ - my ($x, $output, $err, $in) =('', '', '', '') ; - - if (ref $_[0] ) { - $in = $_[0] ; - croak "not a scalar reference" unless ref $in eq 'SCALAR' ; - } - else { - $in = \$_[0] ; - } - - $] >= 5.008 and (utf8::downgrade($$in, 1) - or croak "Wide character in uncompress"); - - $x = new Compress::Raw::Zlib::Inflate -ConsumeInput => 0 or return undef ; - - $err = $x->inflate($in, $output) ; - return undef unless $err == Z_STREAM_END() ; - - return $output ; -} - - - -sub deflateInit(@) -{ - my ($got) = ParseParameters(0, - { - 'Bufsize' => [1, 1, Parse_unsigned, 4096], - 'Level' => [1, 1, Parse_signed, Z_DEFAULT_COMPRESSION()], - 'Method' => [1, 1, Parse_unsigned, Z_DEFLATED()], - 'WindowBits' => [1, 1, Parse_signed, MAX_WBITS()], - 'MemLevel' => [1, 1, Parse_unsigned, MAX_MEM_LEVEL()], - 'Strategy' => [1, 1, Parse_unsigned, Z_DEFAULT_STRATEGY()], - 'Dictionary' => [1, 1, Parse_any, ""], - }, @_ ) ; - - croak "Compress::Zlib::deflateInit: Bufsize must be >= 1, you specified " . - $got->value('Bufsize') - unless $got->value('Bufsize') >= 1; - - my $obj ; - - my $status = 0 ; - ($obj, $status) = - Compress::Raw::Zlib::_deflateInit(0, - $got->value('Level'), - $got->value('Method'), - $got->value('WindowBits'), - $got->value('MemLevel'), - $got->value('Strategy'), - $got->value('Bufsize'), - $got->value('Dictionary')) ; - - my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldDeflate" : undef) ; - return wantarray ? ($x, $status) : $x ; -} - -sub inflateInit(@) -{ - my ($got) = ParseParameters(0, - { - 'Bufsize' => [1, 1, Parse_unsigned, 4096], - 'WindowBits' => [1, 1, Parse_signed, MAX_WBITS()], - 'Dictionary' => [1, 1, Parse_any, ""], - }, @_) ; - - - croak "Compress::Zlib::inflateInit: Bufsize must be >= 1, you specified " . - $got->value('Bufsize') - unless $got->value('Bufsize') >= 1; - - my $status = 0 ; - my $obj ; - ($obj, $status) = Compress::Raw::Zlib::_inflateInit(FLAG_CONSUME_INPUT, - $got->value('WindowBits'), - $got->value('Bufsize'), - $got->value('Dictionary')) ; - - my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldInflate" : undef) ; - - wantarray ? ($x, $status) : $x ; -} - -package Zlib::OldDeflate ; - -our (@ISA); -@ISA = qw(Compress::Raw::Zlib::deflateStream); - - -sub deflate -{ - my $self = shift ; - my $output ; - - my $status = $self->SUPER::deflate($_[0], $output) ; - wantarray ? ($output, $status) : $output ; -} - -sub flush -{ - my $self = shift ; - my $output ; - my $flag = shift || Compress::Zlib::Z_FINISH(); - my $status = $self->SUPER::flush($output, $flag) ; - - wantarray ? ($output, $status) : $output ; -} - -package Zlib::OldInflate ; - -our (@ISA); -@ISA = qw(Compress::Raw::Zlib::inflateStream); - -sub inflate -{ - my $self = shift ; - my $output ; - my $status = $self->SUPER::inflate($_[0], $output) ; - wantarray ? ($output, $status) : $output ; -} - -package Compress::Zlib ; - -use IO::Compress::Gzip::Constants 2.015 ; - -sub memGzip($) -{ - my $out; - - # if the deflation buffer isn't a reference, make it one - my $string = (ref $_[0] ? $_[0] : \$_[0]) ; - - $] >= 5.008 and (utf8::downgrade($$string, 1) - or croak "Wide character in memGzip"); - - IO::Compress::Gzip::gzip($string, \$out, Minimal => 1) - or return undef ; - - return $out; -} - - -sub _removeGzipHeader($) -{ - my $string = shift ; - - return Z_DATA_ERROR() - if length($$string) < GZIP_MIN_HEADER_SIZE ; - - my ($magic1, $magic2, $method, $flags, $time, $xflags, $oscode) = - unpack ('CCCCVCC', $$string); - - return Z_DATA_ERROR() - unless $magic1 == GZIP_ID1 and $magic2 == GZIP_ID2 and - $method == Z_DEFLATED() and !($flags & GZIP_FLG_RESERVED) ; - substr($$string, 0, GZIP_MIN_HEADER_SIZE) = '' ; - - # skip extra field - if ($flags & GZIP_FLG_FEXTRA) - { - return Z_DATA_ERROR() - if length($$string) < GZIP_FEXTRA_HEADER_SIZE ; - - my ($extra_len) = unpack ('v', $$string); - $extra_len += GZIP_FEXTRA_HEADER_SIZE; - return Z_DATA_ERROR() - if length($$string) < $extra_len ; - - substr($$string, 0, $extra_len) = ''; - } - - # skip orig name - if ($flags & GZIP_FLG_FNAME) - { - my $name_end = index ($$string, GZIP_NULL_BYTE); - return Z_DATA_ERROR() - if $name_end == -1 ; - substr($$string, 0, $name_end + 1) = ''; - } - - # skip comment - if ($flags & GZIP_FLG_FCOMMENT) - { - my $comment_end = index ($$string, GZIP_NULL_BYTE); - return Z_DATA_ERROR() - if $comment_end == -1 ; - substr($$string, 0, $comment_end + 1) = ''; - } - - # skip header crc - if ($flags & GZIP_FLG_FHCRC) - { - return Z_DATA_ERROR() - if length ($$string) < GZIP_FHCRC_SIZE ; - substr($$string, 0, GZIP_FHCRC_SIZE) = ''; - } - - return Z_OK(); -} - - -sub memGunzip($) -{ - # if the buffer isn't a reference, make it one - my $string = (ref $_[0] ? $_[0] : \$_[0]); - - $] >= 5.008 and (utf8::downgrade($$string, 1) - or croak "Wide character in memGunzip"); - - _removeGzipHeader($string) == Z_OK() - or return undef; - - my $bufsize = length $$string > 4096 ? length $$string : 4096 ; - my $x = new Compress::Raw::Zlib::Inflate({-WindowBits => - MAX_WBITS(), - -Bufsize => $bufsize}) - - or return undef; - - my $output = "" ; - my $status = $x->inflate($string, $output); - return undef - unless $status == Z_STREAM_END(); - - if (length $$string >= 8) - { - my ($crc, $len) = unpack ("VV", substr($$string, 0, 8)); - substr($$string, 0, 8) = ''; - return undef - unless $len == length($output) and - $crc == crc32($output); - } - else - { - $$string = ''; - } - return $output; -} - -# Autoload methods go after __END__, and are processed by the autosplit program. - -1; -__END__ - - -=head1 NAME - -Compress::Zlib - Interface to zlib compression library - -=head1 SYNOPSIS - - use Compress::Zlib ; - - ($d, $status) = deflateInit( [OPT] ) ; - $status = $d->deflate($input, $output) ; - $status = $d->flush([$flush_type]) ; - $d->deflateParams(OPTS) ; - $d->deflateTune(OPTS) ; - $d->dict_adler() ; - $d->crc32() ; - $d->adler32() ; - $d->total_in() ; - $d->total_out() ; - $d->msg() ; - $d->get_Strategy(); - $d->get_Level(); - $d->get_BufSize(); - - ($i, $status) = inflateInit( [OPT] ) ; - $status = $i->inflate($input, $output [, $eof]) ; - $status = $i->inflateSync($input) ; - $i->dict_adler() ; - $d->crc32() ; - $d->adler32() ; - $i->total_in() ; - $i->total_out() ; - $i->msg() ; - $d->get_BufSize(); - - $dest = compress($source) ; - $dest = uncompress($source) ; - - $gz = gzopen($filename or filehandle, $mode) ; - $bytesread = $gz->gzread($buffer [,$size]) ; - $bytesread = $gz->gzreadline($line) ; - $byteswritten = $gz->gzwrite($buffer) ; - $status = $gz->gzflush($flush) ; - $offset = $gz->gztell() ; - $status = $gz->gzseek($offset, $whence) ; - $status = $gz->gzclose() ; - $status = $gz->gzeof() ; - $status = $gz->gzsetparams($level, $strategy) ; - $errstring = $gz->gzerror() ; - $gzerrno - - $dest = Compress::Zlib::memGzip($buffer) ; - $dest = Compress::Zlib::memGunzip($buffer) ; - - $crc = adler32($buffer [,$crc]) ; - $crc = crc32($buffer [,$crc]) ; - - $crc = adler32_combine($crc1, $crc2, $len2)l - $crc = crc32_combine($adler1, $adler2, $len2) - - ZLIB_VERSION - ZLIB_VERNUM - -=head1 DESCRIPTION - -The I module provides a Perl interface to the I -compression library (see L for details about where to get -I). - -The C module can be split into two general areas of -functionality, namely a simple read/write interface to I files -and a low-level in-memory compression/decompression interface. - -Each of these areas will be discussed in the following sections. - -=head2 Notes for users of Compress::Zlib version 1 - -The main change in C version 2.x is that it does not now -interface directly to the zlib library. Instead it uses the -C and C modules for -reading/writing gzip files, and the C module for some -low-level zlib access. - -The interface provided by version 2 of this module should be 100% backward -compatible with version 1. If you find a difference in the expected -behaviour please contact the author (See L). See L - -With the creation of the C and C modules no -new features are planned for C - the new modules do -everything that C does and then some. Development on -C will be limited to bug fixes only. - -If you are writing new code, your first port of call should be one of the -new C or C modules. - -=head1 GZIP INTERFACE - -A number of functions are supplied in I for reading and writing -I files that conform to RFC 1952. This module provides an interface -to most of them. - -If you have previously used C 1.x, the following -enhancements/changes have been made to the C interface: - -=over 5 - -=item 1 - -If you want to to open either STDIN or STDOUT with C, you can now -optionally use the special filename "C<->" as a synonym for C<\*STDIN> and -C<\*STDOUT>. - -=item 2 - -In C version 1.x, C used the zlib library to open -the underlying file. This made things especially tricky when a Perl -filehandle was passed to C. Behind the scenes the numeric C file -descriptor had to be extracted from the Perl filehandle and this passed to -the zlib library. - -Apart from being non-portable to some operating systems, this made it -difficult to use C in situations where you wanted to extract/create -a gzip data stream that is embedded in a larger file, without having to -resort to opening and closing the file multiple times. - -It also made it impossible to pass a perl filehandle that wasn't associated -with a real filesystem file, like, say, an C. - -In C version 2.x, the C interface has been -completely rewritten to use the L -for writing gzip files and L -for reading gzip files. None of the limitations mentioned above apply. - -=item 3 - -Addition of C to provide a restricted C interface. - -=item 4. - -Added C. - -=back - -A more complete and flexible interface for reading/writing gzip -files/buffers is included with the module C. See -L and -L for more details. - -=over 5 - -=item B<$gz = gzopen($filename, $mode)> - -=item B<$gz = gzopen($filehandle, $mode)> - -This function opens either the I file C<$filename> for reading or -writing or attaches to the opened filehandle, C<$filehandle>. -It returns an object on success and C on failure. - -When writing a gzip file this interface will I create the smallest -possible gzip header (exactly 10 bytes). If you want greater control over -what gets stored in the gzip header (like the original filename or a -comment) use L instead. Similarly if -you want to read the contents of the gzip header use -L. - -The second parameter, C<$mode>, is used to specify whether the file is -opened for reading or writing and to optionally specify a compression -level and compression strategy when writing. The format of the C<$mode> -parameter is similar to the mode parameter to the 'C' function C, -so "rb" is used to open for reading, "wb" for writing and "ab" for -appending (writing at the end of the file). - -To specify a compression level when writing, append a digit between 0 -and 9 to the mode string -- 0 means no compression and 9 means maximum -compression. -If no compression level is specified Z_DEFAULT_COMPRESSION is used. - -To specify the compression strategy when writing, append 'f' for filtered -data, 'h' for Huffman only compression, or 'R' for run-length encoding. -If no strategy is specified Z_DEFAULT_STRATEGY is used. - -So, for example, "wb9" means open for writing with the maximum compression -using the default strategy and "wb4R" means open for writing with compression -level 4 and run-length encoding. - -Refer to the I documentation for the exact format of the C<$mode> -parameter. - -=item B<$bytesread = $gz-Egzread($buffer [, $size]) ;> - -Reads C<$size> bytes from the compressed file into C<$buffer>. If -C<$size> is not specified, it will default to 4096. If the scalar -C<$buffer> is not large enough, it will be extended automatically. - -Returns the number of bytes actually read. On EOF it returns 0 and in -the case of an error, -1. - -=item B<$bytesread = $gz-Egzreadline($line) ;> - -Reads the next line from the compressed file into C<$line>. - -Returns the number of bytes actually read. On EOF it returns 0 and in -the case of an error, -1. - -It is legal to intermix calls to C and C. - -To maintain backward compatibility with version 1.x of this module -C ignores the C<$/> variable - it I uses the string -C<"\n"> as the line delimiter. - -If you want to read a gzip file a line at a time and have it respect the -C<$/> variable (or C<$INPUT_RECORD_SEPARATOR>, or C<$RS> when C is -in use) see L. - -=item B<$byteswritten = $gz-Egzwrite($buffer) ;> - -Writes the contents of C<$buffer> to the compressed file. Returns the -number of bytes actually written, or 0 on error. - -=item B<$status = $gz-Egzflush($flush_type) ;> - -Flushes all pending output into the compressed file. - -This method takes an optional parameter, C<$flush_type>, that controls -how the flushing will be carried out. By default the C<$flush_type> -used is C. Other valid values for C<$flush_type> are -C, C, C and C. It is -strongly recommended that you only set the C parameter if -you fully understand the implications of what it does - overuse of C -can seriously degrade the level of compression achieved. See the C -documentation for details. - -Returns 0 on success. - -=item B<$offset = $gz-Egztell() ;> - -Returns the uncompressed file offset. - -=item B<$status = $gz-Egzseek($offset, $whence) ;> - -Provides a sub-set of the C functionality, with the restriction -that it is only legal to seek forward in the compressed file. -It is a fatal error to attempt to seek backward. - -When opened for writing, empty parts of the file will have NULL (0x00) -bytes written to them. - -The C<$whence> parameter should be one of SEEK_SET, SEEK_CUR or SEEK_END. - -Returns 1 on success, 0 on failure. - -=item B<$gz-Egzclose> - -Closes the compressed file. Any pending data is flushed to the file -before it is closed. - -Returns 0 on success. - -=item B<$gz-Egzsetparams($level, $strategy> - -Change settings for the deflate stream C<$gz>. - -The list of the valid options is shown below. Options not specified -will remain unchanged. - -Note: This method is only available if you are running zlib 1.0.6 or better. - -=over 5 - -=item B<$level> - -Defines the compression level. Valid values are 0 through 9, -C, C, C, and -C. - -=item B<$strategy> - -Defines the strategy used to tune the compression. The valid values are -C, C and C. - -=back - -=item B<$gz-Egzerror> - -Returns the I error message or number for the last operation -associated with C<$gz>. The return value will be the I error -number when used in a numeric context and the I error message -when used in a string context. The I error number constants, -shown below, are available for use. - - Z_OK - Z_STREAM_END - Z_ERRNO - Z_STREAM_ERROR - Z_DATA_ERROR - Z_MEM_ERROR - Z_BUF_ERROR - -=item B<$gzerrno> - -The C<$gzerrno> scalar holds the error code associated with the most -recent I routine. Note that unlike C, the error is -I associated with a particular file. - -As with C it returns an error number in numeric context and -an error message in string context. Unlike C though, the -error message will correspond to the I message when the error is -associated with I itself, or the UNIX error message when it is -not (i.e. I returned C). - -As there is an overlap between the error numbers used by I and -UNIX, C<$gzerrno> should only be used to check for the presence of -I error in numeric context. Use C to check for specific -I errors. The I example below shows how the variable can -be used safely. - -=back - -=head2 Examples - -Here is an example script which uses the interface. It implements a -I function. - - use strict ; - use warnings ; - - use Compress::Zlib ; - - # use stdin if no files supplied - @ARGV = '-' unless @ARGV ; - - foreach my $file (@ARGV) { - my $buffer ; - - my $gz = gzopen($file, "rb") - or die "Cannot open $file: $gzerrno\n" ; - - print $buffer while $gz->gzread($buffer) > 0 ; - - die "Error reading from $file: $gzerrno" . ($gzerrno+0) . "\n" - if $gzerrno != Z_STREAM_END ; - - $gz->gzclose() ; - } - -Below is a script which makes use of C. It implements a -very simple I like script. - - use strict ; - use warnings ; - - use Compress::Zlib ; - - die "Usage: gzgrep pattern [file...]\n" - unless @ARGV >= 1; - - my $pattern = shift ; - - # use stdin if no files supplied - @ARGV = '-' unless @ARGV ; - - foreach my $file (@ARGV) { - my $gz = gzopen($file, "rb") - or die "Cannot open $file: $gzerrno\n" ; - - while ($gz->gzreadline($_) > 0) { - print if /$pattern/ ; - } - - die "Error reading from $file: $gzerrno\n" - if $gzerrno != Z_STREAM_END ; - - $gz->gzclose() ; - } - -This script, I, does the opposite of the I script -above. It reads from standard input and writes a gzip data stream to -standard output. - - use strict ; - use warnings ; - - use Compress::Zlib ; - - binmode STDOUT; # gzopen only sets it on the fd - - my $gz = gzopen(\*STDOUT, "wb") - or die "Cannot open stdout: $gzerrno\n" ; - - while (<>) { - $gz->gzwrite($_) - or die "error writing: $gzerrno\n" ; - } - - $gz->gzclose ; - -=head2 Compress::Zlib::memGzip - -This function is used to create an in-memory gzip file with the minimum -possible gzip header (exactly 10 bytes). - - $dest = Compress::Zlib::memGzip($buffer) ; - -If successful, it returns the in-memory gzip file, otherwise it returns -undef. - -The C<$buffer> parameter can either be a scalar or a scalar reference. - -See L for an alternative way to -carry out in-memory gzip compression. - -=head2 Compress::Zlib::memGunzip - -This function is used to uncompress an in-memory gzip file. - - $dest = Compress::Zlib::memGunzip($buffer) ; - -If successful, it returns the uncompressed gzip file, otherwise it -returns undef. - -The C<$buffer> parameter can either be a scalar or a scalar reference. The -contents of the C<$buffer> parameter are destroyed after calling this function. - -See L for an alternative way -to carry out in-memory gzip uncompression. - -=head1 COMPRESS/UNCOMPRESS - -Two functions are provided to perform in-memory compression/uncompression of -RFC 1950 data streams. They are called C and C. - -=over 5 - -=item B<$dest = compress($source [, $level] ) ;> - -Compresses C<$source>. If successful it returns the compressed -data. Otherwise it returns I. - -The source buffer, C<$source>, can either be a scalar or a scalar -reference. - -The C<$level> parameter defines the compression level. Valid values are -0 through 9, C, C, -C, and C. -If C<$level> is not specified C will be used. - -=item B<$dest = uncompress($source) ;> - -Uncompresses C<$source>. If successful it returns the uncompressed -data. Otherwise it returns I. - -The source buffer can either be a scalar or a scalar reference. - -=back - -Please note: the two functions defined above are I compatible with -the Unix commands of the same name. - -See L and L included with -this distribution for an alternative interface for reading/writing RFC 1950 -files/buffers. - -=head1 Deflate Interface - -This section defines an interface that allows in-memory compression using -the I interface provided by zlib. - -Here is a definition of the interface available: - -=head2 B<($d, $status) = deflateInit( [OPT] )> - -Initialises a deflation stream. - -It combines the features of the I functions C, -C and C. - -If successful, it will return the initialised deflation stream, C<$d> -and C<$status> of C in a list context. In scalar context it -returns the deflation stream, C<$d>, only. - -If not successful, the returned deflation stream (C<$d>) will be -I and C<$status> will hold the exact I error code. - -The function optionally takes a number of named options specified as -C<< -Name=>value >> pairs. This allows individual options to be -tailored without having to specify them all in the parameter list. - -For backward compatibility, it is also possible to pass the parameters -as a reference to a hash containing the name=>value pairs. - -The function takes one optional parameter, a reference to a hash. The -contents of the hash allow the deflation interface to be tailored. - -Here is a list of the valid options: - -=over 5 - -=item B<-Level> - -Defines the compression level. Valid values are 0 through 9, -C, C, C, and -C. - -The default is Z_DEFAULT_COMPRESSION. - -=item B<-Method> - -Defines the compression method. The only valid value at present (and -the default) is Z_DEFLATED. - -=item B<-WindowBits> - -To create an RFC 1950 data stream, set C to a positive number. - -To create an RFC 1951 data stream, set C to C<-MAX_WBITS>. - -For a full definition of the meaning and valid values for C refer -to the I documentation for I. - -Defaults to MAX_WBITS. - -=item B<-MemLevel> - -For a definition of the meaning and valid values for C -refer to the I documentation for I. - -Defaults to MAX_MEM_LEVEL. - -=item B<-Strategy> - -Defines the strategy used to tune the compression. The valid values are -C, C and C. - -The default is Z_DEFAULT_STRATEGY. - -=item B<-Dictionary> - -When a dictionary is specified I will automatically -call C directly after calling C. The -Adler32 value for the dictionary can be obtained by calling the method -C<$d->dict_adler()>. - -The default is no dictionary. - -=item B<-Bufsize> - -Sets the initial size for the deflation buffer. If the buffer has to be -reallocated to increase the size, it will grow in increments of -C. - -The default is 4096. - -=back - -Here is an example of using the C optional parameter list -to override the default buffer size and compression level. All other -options will take their default values. - - deflateInit( -Bufsize => 300, - -Level => Z_BEST_SPEED ) ; - -=head2 B<($out, $status) = $d-Edeflate($buffer)> - -Deflates the contents of C<$buffer>. The buffer can either be a scalar -or a scalar reference. When finished, C<$buffer> will be -completely processed (assuming there were no errors). If the deflation -was successful it returns the deflated output, C<$out>, and a status -value, C<$status>, of C. - -On error, C<$out> will be I and C<$status> will contain the -I error code. - -In a scalar context C will return C<$out> only. - -As with the I function in I, it is not necessarily the -case that any output will be produced by this method. So don't rely on -the fact that C<$out> is empty for an error test. - -=head2 B<($out, $status) = $d-Eflush()> -=head2 B<($out, $status) = $d-Eflush($flush_type)> - -Typically used to finish the deflation. Any pending output will be -returned via C<$out>. -C<$status> will have a value C if successful. - -In a scalar context C will return C<$out> only. - -Note that flushing can seriously degrade the compression ratio, so it -should only be used to terminate a decompression (using C) or -when you want to create a I (using C). - -By default the C used is C. Other valid values -for C are C, C, C -and C. It is strongly recommended that you only set the -C parameter if you fully understand the implications of -what it does. See the C documentation for details. - -=head2 B<$status = $d-EdeflateParams([OPT])> - -Change settings for the deflate stream C<$d>. - -The list of the valid options is shown below. Options not specified -will remain unchanged. - -=over 5 - -=item B<-Level> - -Defines the compression level. Valid values are 0 through 9, -C, C, C, and -C. - -=item B<-Strategy> - -Defines the strategy used to tune the compression. The valid values are -C, C and C. - -=back - -=head2 B<$d-Edict_adler()> - -Returns the adler32 value for the dictionary. - -=head2 B<$d-Emsg()> - -Returns the last error message generated by zlib. - -=head2 B<$d-Etotal_in()> - -Returns the total number of bytes uncompressed bytes input to deflate. - -=head2 B<$d-Etotal_out()> - -Returns the total number of compressed bytes output from deflate. - -=head2 Example - -Here is a trivial example of using C. It simply reads standard -input, deflates it and writes it to standard output. - - use strict ; - use warnings ; - - use Compress::Zlib ; - - binmode STDIN; - binmode STDOUT; - my $x = deflateInit() - or die "Cannot create a deflation stream\n" ; - - my ($output, $status) ; - while (<>) - { - ($output, $status) = $x->deflate($_) ; - - $status == Z_OK - or die "deflation failed\n" ; - - print $output ; - } - - ($output, $status) = $x->flush() ; - - $status == Z_OK - or die "deflation failed\n" ; - - print $output ; - -=head1 Inflate Interface - -This section defines the interface available that allows in-memory -uncompression using the I interface provided by zlib. - -Here is a definition of the interface: - -=head2 B<($i, $status) = inflateInit()> - -Initialises an inflation stream. - -In a list context it returns the inflation stream, C<$i>, and the -I status code in C<$status>. In a scalar context it returns the -inflation stream only. - -If successful, C<$i> will hold the inflation stream and C<$status> will -be C. - -If not successful, C<$i> will be I and C<$status> will hold the -I error code. - -The function optionally takes a number of named options specified as -C<< -Name=>value >> pairs. This allows individual options to be -tailored without having to specify them all in the parameter list. - -For backward compatibility, it is also possible to pass the parameters -as a reference to a hash containing the name=>value pairs. - -The function takes one optional parameter, a reference to a hash. The -contents of the hash allow the deflation interface to be tailored. - -Here is a list of the valid options: - -=over 5 - -=item B<-WindowBits> - -To uncompress an RFC 1950 data stream, set C to a positive number. - -To uncompress an RFC 1951 data stream, set C to C<-MAX_WBITS>. - -For a full definition of the meaning and valid values for C refer -to the I documentation for I. - -Defaults to MAX_WBITS. - -=item B<-Bufsize> - -Sets the initial size for the inflation buffer. If the buffer has to be -reallocated to increase the size, it will grow in increments of -C. - -Default is 4096. - -=item B<-Dictionary> - -The default is no dictionary. - -=back - -Here is an example of using the C optional parameter to -override the default buffer size. - - inflateInit( -Bufsize => 300 ) ; - -=head2 B<($out, $status) = $i-Einflate($buffer)> - -Inflates the complete contents of C<$buffer>. The buffer can either be -a scalar or a scalar reference. - -Returns C if successful and C if the end of the -compressed data has been successfully reached. -If not successful, C<$out> will be I and C<$status> will hold -the I error code. - -The C<$buffer> parameter is modified by C. On completion it -will contain what remains of the input buffer after inflation. This -means that C<$buffer> will be an empty string when the return status is -C. When the return status is C the C<$buffer> -parameter will contains what (if anything) was stored in the input -buffer after the deflated data stream. - -This feature is useful when processing a file format that encapsulates -a compressed data stream (e.g. gzip, zip). - -=head2 B<$status = $i-EinflateSync($buffer)> - -Scans C<$buffer> until it reaches either a I or the -end of the buffer. - -If a I is found, C is returned and C<$buffer> -will be have all data up to the flush point removed. This can then be -passed to the C method. - -Any other return code means that a flush point was not found. If more -data is available, C can be called repeatedly with more -compressed data until the flush point is found. - -=head2 B<$i-Edict_adler()> - -Returns the adler32 value for the dictionary. - -=head2 B<$i-Emsg()> - -Returns the last error message generated by zlib. - -=head2 B<$i-Etotal_in()> - -Returns the total number of bytes compressed bytes input to inflate. - -=head2 B<$i-Etotal_out()> - -Returns the total number of uncompressed bytes output from inflate. - -=head2 Example - -Here is an example of using C. - - use strict ; - use warnings ; - - use Compress::Zlib ; - - my $x = inflateInit() - or die "Cannot create a inflation stream\n" ; - - my $input = '' ; - binmode STDIN; - binmode STDOUT; - - my ($output, $status) ; - while (read(STDIN, $input, 4096)) - { - ($output, $status) = $x->inflate(\$input) ; - - print $output - if $status == Z_OK or $status == Z_STREAM_END ; - - last if $status != Z_OK ; - } - - die "inflation failed\n" - unless $status == Z_STREAM_END ; - -=head1 CHECKSUM FUNCTIONS - -Two functions are provided by I to calculate checksums. For the -Perl interface, the order of the two parameters in both functions has -been reversed. This allows both running checksums and one off -calculations to be done. - - $crc = adler32($buffer [,$crc]) ; - $crc = crc32($buffer [,$crc]) ; - -The buffer parameters can either be a scalar or a scalar reference. - -If the $crc parameters is C, the crc value will be reset. - -If you have built this module with zlib 1.2.3 or better, two more -CRC-related functions are available. - - $crc = adler32_combine($crc1, $crc2, $len2)l - $crc = crc32_combine($adler1, $adler2, $len2) - -These functions allow checksums to be merged. - -=head1 CONSTANTS - -All the I constants are automatically imported when you make use -of I. - -=head1 SEE ALSO - -L, L, L, L, L, L, L, L, L, L, L, L, L, L - -L - -L, L, -L, -L - -For RFC 1950, 1951 and 1952 see -F, -F and -F - -The I compression library was written by Jean-loup Gailly -F and Mark Adler F. - -The primary site for the I compression library is -F. - -The primary site for gzip is F. - -=head1 AUTHOR - -This module was written by Paul Marquess, F. - -=head1 MODIFICATION HISTORY - -See the Changes file. - -=head1 COPYRIGHT AND LICENSE - -Copyright (c) 1995-2008 Paul Marquess. All rights reserved. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - diff --git a/ext/Compress-Zlib/pod/FAQ.pod b/ext/Compress-Zlib/pod/FAQ.pod deleted file mode 100644 index d590412f92..0000000000 --- a/ext/Compress-Zlib/pod/FAQ.pod +++ /dev/null @@ -1,125 +0,0 @@ - -=head1 NAME - -Compress::Zlib::FAQ -- Frequently Asked Questions about Compress::Zlib - -=head1 DESCRIPTION - -Common questions answered. - -=head2 Compatibility with Unix compress/uncompress. - -Although C has a pair of functions called C and -C, they are I related to the Unix programs of the same -name. The C module is not compatible with Unix -C. - -If you have the C program available, you can use this to read -compressed files - - open F, "uncompress -c $filename |"; - while () - { - ... - -Alternatively, if you have the C program available, you can use -this to read compressed files - - open F, "gunzip -c $filename |"; - while () - { - ... - -and this to write compress files, if you have the C program -available - - open F, "| compress -c $filename "; - print F "data"; - ... - close F ; - -=head2 Accessing .tar.Z files - -The C module can optionally use C (via the -C module) to access tar files that have been compressed with -C. Unfortunately tar files compressed with the Unix C -utility cannot be read by C and so cannot be directly -accessed by C. - -If the C or C programs are available, you can use one -of these workarounds to read C<.tar.Z> files from C - -Firstly with C - - use strict; - use warnings; - use Archive::Tar; - - open F, "uncompress -c $filename |"; - my $tar = Archive::Tar->new(*F); - ... - -and this with C - - use strict; - use warnings; - use Archive::Tar; - - open F, "gunzip -c $filename |"; - my $tar = Archive::Tar->new(*F); - ... - -Similarly, if the C program is available, you can use this to -write a C<.tar.Z> file - - use strict; - use warnings; - use Archive::Tar; - use IO::File; - - my $fh = new IO::File "| compress -c >$filename"; - my $tar = Archive::Tar->new(); - ... - $tar->write($fh); - $fh->close ; - -=head2 Accessing Zip Files - -This module does not support reading/writing zip files. - -Support for reading/writing zip files is included with the -C and C modules. - -The primary focus of the C and C -modules is to provide an C compatible streaming read/write -interface to zip files/buffers. They are not fully flegged archivers. If -you are looking for an archiver check out the C module. You -can find it on CPAN at - - http://www.cpan.org/modules/by-module/Archive/Archive-Zip-*.tar.gz - -=head1 SEE ALSO - -L, L, L, L, L, L, L, L, L, L, L, L, L, L, L - -L - -L, L, -L, -L - -=head1 AUTHOR - -This module was written by Paul Marquess, F. - -=head1 MODIFICATION HISTORY - -See the Changes file. - -=head1 COPYRIGHT AND LICENSE - -Copyright (c) 2005-2008 Paul Marquess. All rights reserved. - -This program is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - diff --git a/ext/Compress-Zlib/private/MakeUtil.pm b/ext/Compress-Zlib/private/MakeUtil.pm deleted file mode 100644 index e595910654..0000000000 --- a/ext/Compress-Zlib/private/MakeUtil.pm +++ /dev/null @@ -1,381 +0,0 @@ -package MakeUtil ; -package main ; - -use strict ; - -use Config qw(%Config); -use File::Copy; - -my $VERSION = '1.0'; - - -BEGIN -{ - eval { require File::Spec::Functions ; File::Spec::Functions->import() } ; - if ($@) - { - *catfile = sub { return "$_[0]/$_[1]" } - } -} - -require VMS::Filespec if $^O eq 'VMS'; - - -unless($ENV{PERL_CORE}) { - $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV; -} - -$ENV{SKIP_FOR_CORE} = 1 if $ENV{PERL_CORE} || $ENV{MY_PERL_CORE} ; - - - -sub MY::libscan -{ - my $self = shift; - my $path = shift; - - return undef - if $path =~ /(~|\.bak|_bak)$/ || - $path =~ /\..*\.sw(o|p)$/ || - $path =~ /\B\.svn\b/; - - return $path; -} - -sub MY::postamble -{ - return '' - if $ENV{PERL_CORE} ; - - my @files = getPerlFiles('MANIFEST'); - - # Note: Once you remove all the layers of shell/makefile escaping - # the regular expression below reads - # - # /^\s*local\s*\(\s*\$^W\s*\)/ - # - my $postamble = ' - -MyTrebleCheck: - @echo Checking for $$^W in files: '. "@files" . ' - @perl -ne \' \ - exit 1 if /^\s*local\s*\(\s*\$$\^W\s*\)/; \ - \' ' . " @files || " . ' \ - (echo found unexpected $$^W ; exit 1) - @echo All is ok. - -'; - - return $postamble; -} - -sub getPerlFiles -{ - my @manifests = @_ ; - - my @files = (); - - for my $manifest (@manifests) - { - my $prefix = './'; - - $prefix = $1 - if $manifest =~ m#^(.*/)#; - - open M, "<$manifest" - or die "Cannot open '$manifest': $!\n"; - while () - { - chomp ; - next if /^\s*#/ || /^\s*$/ ; - - s/^\s+//; - s/\s+$//; - - /^(\S+)\s*(.*)$/; - - my ($file, $rest) = ($1, $2); - - if ($file =~ /\.(pm|pl|t)$/ and $file !~ /MakeUtil.pm/) - { - push @files, "$prefix$file"; - } - elsif ($rest =~ /perl/i) - { - push @files, "$prefix$file"; - } - - } - close M; - } - - return @files; -} - -sub UpDowngrade -{ - return if defined $ENV{TipTop}; - - my @files = @_ ; - - # our and use bytes/utf8 is stable from 5.6.0 onward - # warnings is stable from 5.6.1 onward - - # Note: this code assumes that each statement it modifies is not - # split across multiple lines. - - - my $warn_sub = ''; - my $our_sub = '' ; - - my $upgrade ; - my $downgrade ; - my $do_downgrade ; - - my $caller = (caller(1))[3] || ''; - - if ($caller =~ /downgrade/) - { - $downgrade = 1; - } - elsif ($caller =~ /upgrade/) - { - $upgrade = 1; - } - else - { - $do_downgrade = 1 - if $] < 5.006001 ; - } - -# else -# { -# my $opt = shift @ARGV || '' ; -# $upgrade = ($opt =~ /^-upgrade/i); -# $downgrade = ($opt =~ /^-downgrade/i); -# push @ARGV, $opt unless $downgrade || $upgrade; -# } - - - if ($downgrade || $do_downgrade) { - # From: use|no warnings "blah" - # To: local ($^W) = 1; # use|no warnings "blah" - $warn_sub = sub { - s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ; - s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ; - }; - } - #elsif ($] >= 5.006001 || $upgrade) { - elsif ($upgrade) { - # From: local ($^W) = 1; # use|no warnings "blah" - # To: use|no warnings "blah" - $warn_sub = sub { - s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ; - }; - } - - if ($downgrade || $do_downgrade) { - $our_sub = sub { - if ( /^(\s*)our\s+\(\s*([^)]+\s*)\)/ ) { - my $indent = $1; - my $vars = join ' ', split /\s*,\s*/, $2; - $_ = "${indent}use vars qw($vars);\n"; - } - elsif ( /^(\s*)((use|no)\s+(bytes|utf8)\s*;.*)$/) - { - $_ = "$1# $2\n"; - } - }; - } - #elsif ($] >= 5.006000 || $upgrade) { - elsif ($upgrade) { - $our_sub = sub { - if ( /^(\s*)use\s+vars\s+qw\((.*?)\)/ ) { - my $indent = $1; - my $vars = join ', ', split ' ', $2; - $_ = "${indent}our ($vars);\n"; - } - elsif ( /^(\s*)#\s*((use|no)\s+(bytes|utf8)\s*;.*)$/) - { - $_ = "$1$2\n"; - } - }; - } - - if (! $our_sub && ! $warn_sub) { - warn "Up/Downgrade not needed.\n"; - if ($upgrade || $downgrade) - { exit 0 } - else - { return } - } - - foreach (@files) { - #if (-l $_ ) - { doUpDown($our_sub, $warn_sub, $_) } - #else - #{ doUpDownViaCopy($our_sub, $warn_sub, $_) } - } - - warn "Up/Downgrade complete.\n" ; - exit 0 if $upgrade || $downgrade; - -} - - -sub doUpDown -{ - my $our_sub = shift; - my $warn_sub = shift; - - return if -d $_[0]; - - local ($^I) = ($^O eq 'VMS') ? "_bak" : ".bak"; - local (@ARGV) = shift; - - while (<>) - { - print, last if /^__(END|DATA)__/ ; - - &{ $our_sub }() if $our_sub ; - &{ $warn_sub }() if $warn_sub ; - print ; - } - - return if eof ; - - while (<>) - { print } -} - -sub doUpDownViaCopy -{ - my $our_sub = shift; - my $warn_sub = shift; - my $file = shift ; - - use File::Copy ; - - return if -d $file ; - - my $backup = $file . ($^O eq 'VMS') ? "_bak" : ".bak"; - - copy($file, $backup) - or die "Cannot copy $file to $backup: $!"; - - my @keep = (); - - { - open F, "<$file" - or die "Cannot open $file: $!\n" ; - while () - { - if (/^__(END|DATA)__/) - { - push @keep, $_; - last ; - } - - &{ $our_sub }() if $our_sub ; - &{ $warn_sub }() if $warn_sub ; - push @keep, $_; - } - - if (! eof F) - { - while () - { push @keep, $_ } - } - close F; - } - - { - open F, ">$file" - or die "Cannot open $file: $!\n"; - print F @keep ; - close F; - } -} - - -sub FindBrokenDependencies -{ - my $version = shift ; - my %thisModule = map { $_ => 1} @_; - - my @modules = qw( - IO::Compress::Base - IO::Compress::Base::Common - IO::Uncompress::Base - - Compress::Raw::Zlib - Compress::Raw::Bzip2 - - IO::Compress::RawDeflate - IO::Uncompress::RawInflate - IO::Compress::Deflate - IO::Uncompress::Inflate - IO::Compress::Gzip - IO::Compress::Gzip::Constants - IO::Uncompress::Gunzip - IO::Compress::Zip - IO::Uncompress::Unzip - - IO::Compress::Bzip2 - IO::Uncompress::Bunzip2 - - IO::Compress::Lzf - IO::Uncompress::UnLzf - - IO::Compress::Lzop - IO::Uncompress::UnLzop - - Compress::Zlib - ); - - my @broken = (); - - foreach my $module ( grep { ! $thisModule{$_} } @modules) - { - my $hasVersion = getInstalledVersion($module); - - # No need to upgrade if the module isn't installed at all - next - if ! defined $hasVersion; - - # If already have C::Z version 1, then an upgrade to any of the - # IO::Compress modules will not break it. - next - if $module eq 'Compress::Zlib' && $hasVersion < 2; - - if ($hasVersion < $version) - { - push @broken, $module - } - } - - return @broken; -} - -sub getInstalledVersion -{ - my $module = shift; - my $version; - - eval " require $module; "; - - if ($@ eq '') - { - no strict 'refs'; - $version = ${ $module . "::VERSION" }; - $version = 0 - } - - return $version; -} - -package MakeUtil ; - -1; - - diff --git a/ext/Compress-Zlib/t/01version.t b/ext/Compress-Zlib/t/01version.t deleted file mode 100644 index 9d6f283a52..0000000000 --- a/ext/Compress-Zlib/t/01version.t +++ /dev/null @@ -1,42 +0,0 @@ -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't' if -d 't'; - @INC = ("../lib", "lib/compress"); - } -} - -use lib qw(t t/compress); -use strict ; -use warnings ; - -use Test::More ; - -BEGIN -{ - # use Test::NoWarnings, if available - my $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - - plan tests => 2 + $extra ; - - use_ok('Compress::Zlib', 2) ; -} - -# Check zlib_version and ZLIB_VERSION are the same. - -my $zlib_h = ZLIB_VERSION ; -my $libz = Compress::Zlib::zlib_version; - -is($zlib_h, $libz, "ZLIB_VERSION ($zlib_h) matches Compress::Zlib::zlib_version") - or diag < $count + $extra ; - - use_ok('Compress::Zlib', 2) ; - use_ok('IO::Compress::Gzip::Constants') ; - - use_ok('IO::Compress::Gzip', qw($GzipError)) ; -} - - -my $hello = < 1} ) ) ; -ok $x ; -ok $err == Z_OK ; - -my $Answer = ''; -foreach (@hello) -{ - ($X, $status) = $x->deflate($_) ; - last unless $status == Z_OK ; - - $Answer .= $X ; -} - -ok $status == Z_OK ; - -ok ((($X, $status) = $x->flush())[1] == Z_OK ) ; -$Answer .= $X ; - - -my @Answer = split('', $Answer) ; - -my $k; -ok (($k, $err) = inflateInit( {-Bufsize => 1}) ) ; -ok $k ; -ok $err == Z_OK ; - -my $GOT = ''; -my $Z; -foreach (@Answer) -{ - ($Z, $status) = $k->inflate($_) ; - $GOT .= $Z ; - last if $status == Z_STREAM_END or $status != Z_OK ; - -} - -ok $status == Z_STREAM_END ; -ok $GOT eq $hello ; - - -title 'deflate/inflate - small buffer with a number'; -# ============================== - -$hello = 6529 ; - -ok (($x, $err) = deflateInit( {-Bufsize => 1} ) ) ; -ok $x ; -ok $err == Z_OK ; - -ok !defined $x->msg() ; -ok $x->total_in() == 0 ; -ok $x->total_out() == 0 ; -$Answer = ''; -{ - ($X, $status) = $x->deflate($hello) ; - - $Answer .= $X ; -} - -ok $status == Z_OK ; - -ok ((($X, $status) = $x->flush())[1] == Z_OK ) ; -$Answer .= $X ; - -ok !defined $x->msg() ; -ok $x->total_in() == length $hello ; -ok $x->total_out() == length $Answer ; - - -@Answer = split('', $Answer) ; - -ok (($k, $err) = inflateInit( {-Bufsize => 1}) ) ; -ok $k ; -ok $err == Z_OK ; - -ok !defined $k->msg() ; -ok $k->total_in() == 0 ; -ok $k->total_out() == 0 ; - -$GOT = ''; -foreach (@Answer) -{ - ($Z, $status) = $k->inflate($_) ; - $GOT .= $Z ; - last if $status == Z_STREAM_END or $status != Z_OK ; - -} - -ok $status == Z_STREAM_END ; -ok $GOT eq $hello ; - -ok !defined $k->msg() ; -is $k->total_in(), length $Answer ; -ok $k->total_out() == length $hello ; - - - -title 'deflate/inflate - larger buffer'; -# ============================== - - -ok $x = deflateInit() ; - -ok ((($X, $status) = $x->deflate($contents))[1] == Z_OK) ; - -my $Y = $X ; - - -ok ((($X, $status) = $x->flush() )[1] == Z_OK ) ; -$Y .= $X ; - - - -ok $k = inflateInit() ; - -($Z, $status) = $k->inflate($Y) ; - -ok $status == Z_STREAM_END ; -ok $contents eq $Z ; - -title 'deflate/inflate - preset dictionary'; -# =================================== - -my $dictionary = "hello" ; -ok $x = deflateInit({-Level => Z_BEST_COMPRESSION, - -Dictionary => $dictionary}) ; - -my $dictID = $x->dict_adler() ; - -($X, $status) = $x->deflate($hello) ; -ok $status == Z_OK ; -($Y, $status) = $x->flush() ; -ok $status == Z_OK ; -$X .= $Y ; -$x = 0 ; - -ok $k = inflateInit(-Dictionary => $dictionary) ; - -($Z, $status) = $k->inflate($X); -ok $status == Z_STREAM_END ; -ok $k->dict_adler() == $dictID; -ok $hello eq $Z ; - -#$Z=''; -#while (1) { -# ($Z, $status) = $k->inflate($X) ; -# last if $status == Z_STREAM_END or $status != Z_OK ; -#print "status=[$status] hello=[$hello] Z=[$Z]\n"; -#} -#ok $status == Z_STREAM_END ; -#ok $hello eq $Z -# or print "status=[$status] hello=[$hello] Z=[$Z]\n"; - - - - - - -title 'inflate - check remaining buffer after Z_STREAM_END'; -# =================================================== - -{ - ok $x = deflateInit(-Level => Z_BEST_COMPRESSION ) ; - - ($X, $status) = $x->deflate($hello) ; - ok $status == Z_OK ; - ($Y, $status) = $x->flush() ; - ok $status == Z_OK ; - $X .= $Y ; - $x = 0 ; - - ok $k = inflateInit() ; - - my $first = substr($X, 0, 2) ; - my $last = substr($X, 2) ; - ($Z, $status) = $k->inflate($first); - ok $status == Z_OK ; - ok $first eq "" ; - - $last .= "appendage" ; - my $T; - ($T, $status) = $k->inflate($last); - ok $status == Z_STREAM_END ; - ok $hello eq $Z . $T ; - ok $last eq "appendage" ; - -} - -title 'memGzip & memGunzip'; -{ - my $name = "test.gz" ; - my $buffer = <$name") ; - binmode(FH); - print FH $dest ; - close FH ; - - # uncompress with gzopen - ok my $fil = gzopen($name, "rb") ; - - is $fil->gzread($uncomp, 0), 0 ; - ok (($x = $fil->gzread($uncomp)) == $len) ; - - ok ! $fil->gzclose ; - - ok $uncomp eq $buffer ; - - 1 while unlink $name ; - - # now check that memGunzip can deal with it. - my $ungzip = Compress::Zlib::memGunzip($dest) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - # now do the same but use a reference - - $dest = Compress::Zlib::memGzip(\$buffer) ; - ok length $dest ; - - # write it to disk - ok open(FH, ">$name") ; - binmode(FH); - print FH $dest ; - close FH ; - - # uncompress with gzopen - ok $fil = gzopen($name, "rb") ; - - ok (($x = $fil->gzread($uncomp)) == $len) ; - - ok ! $fil->gzclose ; - - ok $uncomp eq $buffer ; - - # now check that memGunzip can deal with it. - my $keep = $dest; - $ungzip = Compress::Zlib::memGunzip(\$dest) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - # check memGunzip can cope with missing gzip trailer - my $minimal = substr($keep, 0, -1) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -2) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -3) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -4) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -5) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -6) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -7) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -8) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok defined $ungzip ; - ok $buffer eq $ungzip ; - - $minimal = substr($keep, 0, -9) ; - $ungzip = Compress::Zlib::memGunzip(\$minimal) ; - ok ! defined $ungzip ; - - - 1 while unlink $name ; - - # check corrupt header -- too short - $dest = "x" ; - my $result = Compress::Zlib::memGunzip($dest) ; - ok !defined $result ; - - # check corrupt header -- full of junk - $dest = "x" x 200 ; - $result = Compress::Zlib::memGunzip($dest) ; - ok !defined $result ; - - # corrupt header - 1st byte wrong - my $bad = $keep ; - substr($bad, 0, 1) = "\xFF" ; - $ungzip = Compress::Zlib::memGunzip(\$bad) ; - ok ! defined $ungzip ; - - # corrupt header - 2st byte wrong - $bad = $keep ; - substr($bad, 1, 1) = "\xFF" ; - $ungzip = Compress::Zlib::memGunzip(\$bad) ; - ok ! defined $ungzip ; - - # corrupt header - method not deflated - $bad = $keep ; - substr($bad, 2, 1) = "\xFF" ; - $ungzip = Compress::Zlib::memGunzip(\$bad) ; - ok ! defined $ungzip ; - - # corrupt header - reserverd bits used - $bad = $keep ; - substr($bad, 3, 1) = "\xFF" ; - $ungzip = Compress::Zlib::memGunzip(\$bad) ; - ok ! defined $ungzip ; - - # corrupt trailer - length wrong - $bad = $keep ; - substr($bad, -8, 4) = "\xFF" x 4 ; - $ungzip = Compress::Zlib::memGunzip(\$bad) ; - ok ! defined $ungzip ; - - # corrupt trailer - CRC wrong - $bad = $keep ; - substr($bad, -4, 4) = "\xFF" x 4 ; - $ungzip = Compress::Zlib::memGunzip(\$bad) ; - ok ! defined $ungzip ; -} - -{ - title "Check all bytes can be handled"; - - my $lex = new LexFile my $name ; - my $data = join '', map { chr } 0x00 .. 0xFF; - $data .= "\r\nabd\r\n"; - - my $fil; - ok $fil = gzopen($name, "wb") ; - is $fil->gzwrite($data), length $data ; - ok ! $fil->gzclose(); - - my $input; - ok $fil = gzopen($name, "rb") ; - is $fil->gzread($input), length $data ; - ok ! $fil->gzclose(); - ok $input eq $data; - - title "Check all bytes can be handled - transparent mode"; - writeFile($name, $data); - ok $fil = gzopen($name, "rb") ; - is $fil->gzread($input), length $data ; - ok ! $fil->gzclose(); - ok $input eq $data; - -} - -title 'memGunzip with a gzopen created file'; -{ - my $name = "test.gz" ; - my $buffer = <gzwrite($buffer) == length $buffer ; - - ok ! $fil->gzclose ; - - my $compr = readFile($name); - ok length $compr ; - my $unc = Compress::Zlib::memGunzip($compr) ; - ok defined $unc ; - ok $buffer eq $unc ; - 1 while unlink $name ; -} - -{ - - # Check - MAX_WBITS - # ================= - - $hello = "Test test test test test"; - @hello = split('', $hello) ; - - ok (($x, $err) = deflateInit( -Bufsize => 1, -WindowBits => -MAX_WBITS() ) ) ; - ok $x ; - ok $err == Z_OK ; - - $Answer = ''; - foreach (@hello) - { - ($X, $status) = $x->deflate($_) ; - last unless $status == Z_OK ; - - $Answer .= $X ; - } - - ok $status == Z_OK ; - - ok ((($X, $status) = $x->flush())[1] == Z_OK ) ; - $Answer .= $X ; - - - @Answer = split('', $Answer) ; - # Undocumented corner -- extra byte needed to get inflate to return - # Z_STREAM_END when done. - push @Answer, " " ; - - ok (($k, $err) = inflateInit(-Bufsize => 1, -WindowBits => -MAX_WBITS()) ) ; - ok $k ; - ok $err == Z_OK ; - - $GOT = ''; - foreach (@Answer) - { - ($Z, $status) = $k->inflate($_) ; - $GOT .= $Z ; - last if $status == Z_STREAM_END or $status != Z_OK ; - - } - - ok $status == Z_STREAM_END ; - ok $GOT eq $hello ; - -} - -{ - # inflateSync - - # create a deflate stream with flush points - - my $hello = "I am a HAL 9000 computer" x 2001 ; - my $goodbye = "Will I dream?" x 2010; - my ($err, $answer, $X, $status, $Answer); - - ok (($x, $err) = deflateInit() ) ; - ok $x ; - ok $err == Z_OK ; - - ($Answer, $status) = $x->deflate($hello) ; - ok $status == Z_OK ; - - # create a flush point - ok ((($X, $status) = $x->flush(Z_FULL_FLUSH))[1] == Z_OK ) ; - $Answer .= $X ; - - ($X, $status) = $x->deflate($goodbye) ; - ok $status == Z_OK ; - $Answer .= $X ; - - ok ((($X, $status) = $x->flush())[1] == Z_OK ) ; - $Answer .= $X ; - - my ($first, @Answer) = split('', $Answer) ; - - my $k; - ok (($k, $err) = inflateInit()) ; - ok $k ; - ok $err == Z_OK ; - - ($Z, $status) = $k->inflate($first) ; - ok $status == Z_OK ; - - # skip to the first flush point. - while (@Answer) - { - my $byte = shift @Answer; - $status = $k->inflateSync($byte) ; - last unless $status == Z_DATA_ERROR; - - } - - ok $status == Z_OK; - - my $GOT = ''; - my $Z = ''; - foreach (@Answer) - { - my $Z = ''; - ($Z, $status) = $k->inflate($_) ; - $GOT .= $Z if defined $Z ; - # print "x $status\n"; - last if $status == Z_STREAM_END or $status != Z_OK ; - - } - - # zlib 1.0.9 returns Z_STREAM_END here, all others return Z_DATA_ERROR - ok $status == Z_DATA_ERROR || $status == Z_STREAM_END ; - ok $GOT eq $goodbye ; - - - # Check inflateSync leaves good data in buffer - $Answer =~ /^(.)(.*)$/ ; - my ($initial, $rest) = ($1, $2); - - - ok (($k, $err) = inflateInit()) ; - ok $k ; - ok $err == Z_OK ; - - ($Z, $status) = $k->inflate($initial) ; - ok $status == Z_OK ; - - $status = $k->inflateSync($rest) ; - ok $status == Z_OK; - - ($GOT, $status) = $k->inflate($rest) ; - - ok $status == Z_DATA_ERROR ; - ok $Z . $GOT eq $goodbye ; -} - -{ - # deflateParams - - my $hello = "I am a HAL 9000 computer" x 2001 ; - my $goodbye = "Will I dream?" x 2010; - my ($input, $err, $answer, $X, $status, $Answer); - - ok (($x, $err) = deflateInit(-Level => Z_BEST_COMPRESSION, - -Strategy => Z_DEFAULT_STRATEGY) ) ; - ok $x ; - ok $err == Z_OK ; - - ok $x->get_Level() == Z_BEST_COMPRESSION; - ok $x->get_Strategy() == Z_DEFAULT_STRATEGY; - - ($Answer, $status) = $x->deflate($hello) ; - ok $status == Z_OK ; - $input .= $hello; - - # error cases - eval { $x->deflateParams() }; - #like $@, mkErr("^Compress::Raw::Zlib::deflateParams needs Level and/or Strategy"); - like $@, "/^Compress::Raw::Zlib::deflateParams needs Level and/or Strategy/"; - - eval { $x->deflateParams(-Joe => 3) }; - like $@, "/^Compress::Raw::Zlib::deflateStream::deflateParams: unknown key value/"; - #like $@, mkErr("^Compress::Raw::Zlib::deflateStream::deflateParams: unknown key value(s) Joe"); - #ok $@ =~ /^Compress::Zlib::deflateStream::deflateParams: unknown key value\(s\) Joe at/ - # or print "# $@\n" ; - - ok $x->get_Level() == Z_BEST_COMPRESSION; - ok $x->get_Strategy() == Z_DEFAULT_STRATEGY; - - # change both Level & Strategy - $status = $x->deflateParams(-Level => Z_BEST_SPEED, -Strategy => Z_HUFFMAN_ONLY) ; - ok $status == Z_OK ; - - ok $x->get_Level() == Z_BEST_SPEED; - ok $x->get_Strategy() == Z_HUFFMAN_ONLY; - - ($X, $status) = $x->deflate($goodbye) ; - ok $status == Z_OK ; - $Answer .= $X ; - $input .= $goodbye; - - # change only Level - $status = $x->deflateParams(-Level => Z_NO_COMPRESSION) ; - ok $status == Z_OK ; - - ok $x->get_Level() == Z_NO_COMPRESSION; - ok $x->get_Strategy() == Z_HUFFMAN_ONLY; - - ($X, $status) = $x->deflate($goodbye) ; - ok $status == Z_OK ; - $Answer .= $X ; - $input .= $goodbye; - - # change only Strategy - $status = $x->deflateParams(-Strategy => Z_FILTERED) ; - ok $status == Z_OK ; - - ok $x->get_Level() == Z_NO_COMPRESSION; - ok $x->get_Strategy() == Z_FILTERED; - - ($X, $status) = $x->deflate($goodbye) ; - ok $status == Z_OK ; - $Answer .= $X ; - $input .= $goodbye; - - ok ((($X, $status) = $x->flush())[1] == Z_OK ) ; - $Answer .= $X ; - - my ($first, @Answer) = split('', $Answer) ; - - my $k; - ok (($k, $err) = inflateInit()) ; - ok $k ; - ok $err == Z_OK ; - - ($Z, $status) = $k->inflate($Answer) ; - - ok $status == Z_STREAM_END - or print "# status $status\n"; - ok $Z eq $input ; -} - -{ - # error cases - - eval { deflateInit(-Level) }; - like $@, '/^Compress::Zlib::deflateInit: Expected even number of parameters, got 1/'; - - eval { inflateInit(-Level) }; - like $@, '/^Compress::Zlib::inflateInit: Expected even number of parameters, got 1/'; - - eval { deflateInit(-Joe => 1) }; - ok $@ =~ /^Compress::Zlib::deflateInit: unknown key value\(s\) Joe at/; - - eval { inflateInit(-Joe => 1) }; - ok $@ =~ /^Compress::Zlib::inflateInit: unknown key value\(s\) Joe at/; - - eval { deflateInit(-Bufsize => 0) }; - ok $@ =~ /^.*?: Bufsize must be >= 1, you specified 0 at/; - - eval { inflateInit(-Bufsize => 0) }; - ok $@ =~ /^.*?: Bufsize must be >= 1, you specified 0 at/; - - eval { deflateInit(-Bufsize => -1) }; - #ok $@ =~ /^.*?: Bufsize must be >= 1, you specified -1 at/; - ok $@ =~ /^Compress::Zlib::deflateInit: Parameter 'Bufsize' must be an unsigned int, got '-1'/; - - eval { inflateInit(-Bufsize => -1) }; - ok $@ =~ /^Compress::Zlib::inflateInit: Parameter 'Bufsize' must be an unsigned int, got '-1'/; - - eval { deflateInit(-Bufsize => "xxx") }; - ok $@ =~ /^Compress::Zlib::deflateInit: Parameter 'Bufsize' must be an unsigned int, got 'xxx'/; - - eval { inflateInit(-Bufsize => "xxx") }; - ok $@ =~ /^Compress::Zlib::inflateInit: Parameter 'Bufsize' must be an unsigned int, got 'xxx'/; - - eval { gzopen([], 0) ; } ; - ok $@ =~ /^gzopen: file parameter is not a filehandle or filename at/ - or print "# $@\n" ; - -# my $x = Symbol::gensym() ; -# eval { gzopen($x, 0) ; } ; -# ok $@ =~ /^gzopen: file parameter is not a filehandle or filename at/ -# or print "# $@\n" ; - -} - -if ($] >= 5.005) -{ - # test inflate with a substr - - ok my $x = deflateInit() ; - - ok ((my ($X, $status) = $x->deflate($contents))[1] == Z_OK) ; - - my $Y = $X ; - - - - ok ((($X, $status) = $x->flush() )[1] == Z_OK ) ; - $Y .= $X ; - - my $append = "Appended" ; - $Y .= $append ; - - ok $k = inflateInit() ; - - #($Z, $status) = $k->inflate(substr($Y, 0, -1)) ; - ($Z, $status) = $k->inflate(substr($Y, 0)) ; - - ok $status == Z_STREAM_END ; - ok $contents eq $Z ; - is $Y, $append; - -} - -if ($] >= 5.005) -{ - # deflate/inflate in scalar context - - ok my $x = deflateInit() ; - - my $X = $x->deflate($contents); - - my $Y = $X ; - - - - $X = $x->flush(); - $Y .= $X ; - - my $append = "Appended" ; - $Y .= $append ; - - ok $k = inflateInit() ; - - $Z = $k->inflate(substr($Y, 0, -1)) ; - #$Z = $k->inflate(substr($Y, 0)) ; - - ok $contents eq $Z ; - is $Y, $append; - -} - -{ - title 'CRC32' ; - - # CRC32 of this data should have the high bit set - # value in ascii is ZgRNtjgSUW - my $data = "\x5a\x67\x52\x4e\x74\x6a\x67\x53\x55\x57"; - my $expected_crc = 0xCF707A2B ; # 3480255019 - - my $crc = crc32($data) ; - is $crc, $expected_crc; -} - -{ - title 'Adler32' ; - - # adler of this data should have the high bit set - # value in ascii is lpscOVsAJiUfNComkOfWYBcPhHZ[bT - my $data = "\x6c\x70\x73\x63\x4f\x56\x73\x41\x4a\x69\x55\x66" . - "\x4e\x43\x6f\x6d\x6b\x4f\x66\x57\x59\x42\x63\x50" . - "\x68\x48\x5a\x5b\x62\x54"; - my $expected_crc = 0xAAD60AC7 ; # 2866154183 - my $crc = adler32($data) ; - is $crc, $expected_crc; -} - -{ - # memGunzip - input > 4K - - my $contents = '' ; - foreach (1 .. 20000) - { $contents .= chr int rand 256 } - - ok my $compressed = Compress::Zlib::memGzip(\$contents) ; - - ok length $compressed > 4096 ; - ok my $out = Compress::Zlib::memGunzip(\$compressed) ; - - ok $contents eq $out ; - is length $out, length $contents ; - - -} - - -{ - # memGunzip Header Corruption Tests - - my $string = < 1, -HeaderCRC => 1 ; - ok $x->write($string) ; - ok $x->close ; - - { - title "Header Corruption - Fingerprint wrong 1st byte" ; - my $buffer = $good ; - substr($buffer, 0, 1) = 'x' ; - - ok ! Compress::Zlib::memGunzip(\$buffer) ; - } - - { - title "Header Corruption - Fingerprint wrong 2nd byte" ; - my $buffer = $good ; - substr($buffer, 1, 1) = "\xFF" ; - - ok ! Compress::Zlib::memGunzip(\$buffer) ; - } - - { - title "Header Corruption - CM not 8"; - my $buffer = $good ; - substr($buffer, 2, 1) = 'x' ; - - ok ! Compress::Zlib::memGunzip(\$buffer) ; - } - - { - title "Header Corruption - Use of Reserved Flags"; - my $buffer = $good ; - substr($buffer, 3, 1) = "\xff"; - - ok ! Compress::Zlib::memGunzip(\$buffer) ; - } - -} - -for my $index ( GZIP_MIN_HEADER_SIZE + 1 .. GZIP_MIN_HEADER_SIZE + GZIP_FEXTRA_HEADER_SIZE + 1) -{ - title "Header Corruption - Truncated in Extra"; - my $string = < 1, -HeaderCRC => 1, Strict => 0, - -ExtraField => "hello" x 10 ; - ok $x->write($string) ; - ok $x->close ; - - substr($truncated, $index) = '' ; - - ok ! Compress::Zlib::memGunzip(\$truncated) ; - - -} - -my $Name = "fred" ; -for my $index ( GZIP_MIN_HEADER_SIZE .. GZIP_MIN_HEADER_SIZE + length($Name) -1) -{ - title "Header Corruption - Truncated in Name"; - my $string = < 1, -Name => $Name; - ok $x->write($string) ; - ok $x->close ; - - substr($truncated, $index) = '' ; - - ok ! Compress::Zlib::memGunzip(\$truncated) ; -} - -my $Comment = "comment" ; -for my $index ( GZIP_MIN_HEADER_SIZE .. GZIP_MIN_HEADER_SIZE + length($Comment) -1) -{ - title "Header Corruption - Truncated in Comment"; - my $string = < $Comment; - ok $x->write($string) ; - ok $x->close ; - - substr($truncated, $index) = '' ; - ok ! Compress::Zlib::memGunzip(\$truncated) ; -} - -for my $index ( GZIP_MIN_HEADER_SIZE .. GZIP_MIN_HEADER_SIZE + GZIP_FHCRC_SIZE -1) -{ - title "Header Corruption - Truncated in CRC"; - my $string = < 1; - ok $x->write($string) ; - ok $x->close ; - - substr($truncated, $index) = '' ; - - ok ! Compress::Zlib::memGunzip(\$truncated) ; -} - -{ - title "memGunzip can cope with a gzip header with all possible fields"; - my $string = < 1, - -Strict => 0, - -HeaderCRC => 1, - -Name => "Fred", - -ExtraField => "Extra", - -Comment => 'Comment'; - ok $x->write($string) ; - ok $x->close ; - - ok defined $buffer ; - - ok my $got = Compress::Zlib::memGunzip($buffer) - or diag "gzerrno is $gzerrno" ; - is $got, $string ; -} - - -{ - # Trailer Corruption tests - - my $string = < 1 ; - ok $x->write($string) ; - ok $x->close ; - - foreach my $trim (-8 .. -1) - { - my $got = $trim + 8 ; - title "Trailer Corruption - Trailer truncated to $got bytes" ; - my $buffer = $good ; - - substr($buffer, $trim) = ''; - - ok my $u = Compress::Zlib::memGunzip(\$buffer) ; - ok $u eq $string; - - } - - { - title "Trailer Corruption - Length Wrong, CRC Correct" ; - my $buffer = $good ; - substr($buffer, -4, 4) = pack('V', 1234); - - ok ! Compress::Zlib::memGunzip(\$buffer) ; - } - - { - title "Trailer Corruption - Length Wrong, CRC Wrong" ; - my $buffer = $good ; - substr($buffer, -4, 4) = pack('V', 1234); - substr($buffer, -8, 4) = pack('V', 1234); - - ok ! Compress::Zlib::memGunzip(\$buffer) ; - - } -} - - -sub slurp -{ - my $name = shift ; - - my $input; - my $fil = gzopen($name, "rb") ; - ok $fil , "opened $name"; - cmp_ok $fil->gzread($input, 50000), ">", 0, "read more than zero bytes"; - ok ! $fil->gzclose(), "closed ok"; - - return $input; -} - -sub trickle -{ - my $name = shift ; - - my $got; - my $input; - $fil = gzopen($name, "rb") ; - ok $fil, "opened ok"; - while ($fil->gzread($input, 50000) > 0) - { - $got .= $input; - $input = ''; - } - ok ! $fil->gzclose(), "closed ok"; - - return $got; - - return $input; -} - -{ - - title "Append & MultiStream Tests"; - # rt.24041 - - my $lex = new LexFile my $name ; - my $data1 = "the is the first"; - my $data2 = "and this is the second"; - my $trailing = "some trailing data"; - - my $fil; - - title "One file"; - $fil = gzopen($name, "wb") ; - ok $fil, "opened first file"; - is $fil->gzwrite($data1), length $data1, "write data1" ; - ok ! $fil->gzclose(), "Closed"; - - is slurp($name), $data1, "got expected data from slurp"; - is trickle($name), $data1, "got expected data from trickle"; - - title "Two files"; - $fil = gzopen($name, "ab") ; - ok $fil, "opened second file"; - is $fil->gzwrite($data2), length $data2, "write data2" ; - ok ! $fil->gzclose(), "Closed"; - - is slurp($name), $data1 . $data2, "got expected data from slurp"; - is trickle($name), $data1 . $data2, "got expected data from trickle"; - - title "Trailing Data"; - open F, ">>$name"; - print F $trailing; - close F; - - is slurp($name), $data1 . $data2 . $trailing, "got expected data from slurp" ; - is trickle($name), $data1 . $data2 . $trailing, "got expected data from trickle" ; -} - -{ - title "gzclose & gzflush return codes"; - # rt.29215 - - my $lex = new LexFile my $name ; - my $data1 = "the is some text"; - my $status; - - $fil = gzopen($name, "wb") ; - ok $fil, "opened first file"; - is $fil->gzwrite($data1), length $data1, "write data1" ; - $status = $fil->gzflush(0xfff); - ok $status, "flush not ok" ; - is $status, Z_STREAM_ERROR; - ok ! $fil->gzflush(), "flush ok" ; - ok ! $fil->gzclose(), "Closed"; -} diff --git a/ext/Compress-Zlib/t/05examples.t b/ext/Compress-Zlib/t/05examples.t deleted file mode 100644 index 48dad73c87..0000000000 --- a/ext/Compress-Zlib/t/05examples.t +++ /dev/null @@ -1,163 +0,0 @@ -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't' if -d 't'; - @INC = ("../lib", "lib/compress"); - } -} - -use lib qw(t t/compress); - -use strict; -use warnings; -use bytes; - -use Test::More ; -use CompTestUtils; -use Compress::Zlib; - -BEGIN -{ - plan(skip_all => "Examples needs Perl 5.005 or better - you have Perl $]" ) - if $] < 5.005 ; - - # use Test::NoWarnings, if available - my $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - - plan tests => 26 + $extra ; -} - - -my $Inc = join " ", map qq["-I$_"] => @INC; -$Inc = '"-MExtUtils::testlib"' - if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ; - -my $Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ; -$Perl = qq["$Perl"] if $^O eq 'MSWin32' ; - -$Perl = "$Perl $Inc -w" ; -my $examples = $ENV{PERL_CORE} ? "../ext/Compress-Zlib/examples" - : "./examples"; - -my $hello1 = <gzwrite($hello1); -$gz->gzclose(); - -$gz = gzopen($file2, "wb"); -$gz->gzwrite($hello2); -$gz->gzclose(); - -sub check -{ - my $command = shift ; - my $expected = shift ; - - my $stderr = 'err.out'; - 1 while unlink $stderr; - - my $cmd = "$command 2>$stderr"; - my $stdout = `$cmd` ; - - my $aok = 1 ; - - $aok &= is $?, 0, " exit status is 0" ; - - $aok &= is readFile($stderr), '', " no stderr" ; - - $aok &= is $stdout, $expected, " expected content is ok" - if defined $expected ; - - if (! $aok) { - diag "Command line: $cmd"; - my ($file, $line) = (caller)[1,2]; - diag "Test called from $file, line $line"; - } - - 1 while unlink $stderr; -} - -# gzcat -# ##### - -title "gzcat - command line" ; -check "$Perl ${examples}/gzcat $file1 $file2", $hello1 . $hello2; - -title "gzcat - stdin" ; -check "$Perl ${examples}/gzcat <$file1 ", $hello1; - - -# gzgrep -# ###### - -title "gzgrep"; -check "$Perl ${examples}/gzgrep the $file1 $file2", - join('', grep(/the/, @hello1, @hello2)); - -for ($file1, $file2, $stderr) { 1 while unlink $_ } ; - - - -# filtdef/filtinf -# ############## - - -writeFile($file1, $hello1) ; -writeFile($file2, $hello2) ; - -title "filtdef" ; -# there's no way to set binmode on backticks in Win32 so we won't use $a later -check "$Perl ${examples}/filtdef $file1 $file2" ; - -title "filtdef | filtinf"; -check "$Perl ${examples}/filtdef $file1 $file2 | $Perl ${examples}/filtinf", - $hello1 . $hello2; -# gzstream -# ######## - -{ - title "gzstream" ; - writeFile($file1, $hello1) ; - check "$Perl ${examples}/gzstream <$file1 >$file2"; - - title "gzcat" ; - check "$Perl ${examples}/gzcat $file2", $hello1 ; -} - -END -{ - for ($file1, $file2, $stderr) { 1 while unlink $_ } ; -} - diff --git a/ext/Compress-Zlib/t/06gzsetp.t b/ext/Compress-Zlib/t/06gzsetp.t deleted file mode 100644 index 0f8d83d5ac..0000000000 --- a/ext/Compress-Zlib/t/06gzsetp.t +++ /dev/null @@ -1,139 +0,0 @@ -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't' if -d 't'; - @INC = ("../lib", "lib/compress"); - } -} - -use lib qw(t t/compress); -use strict; -use warnings; -use bytes; - -use Test::More ; -use CompTestUtils; - -use Compress::Zlib 2 ; - -use IO::Compress::Gzip ; -use IO::Uncompress::Gunzip ; - -use IO::Compress::Deflate ; -use IO::Uncompress::Inflate ; - -use IO::Compress::RawDeflate ; -use IO::Uncompress::RawInflate ; - -our ($extra); - - -BEGIN -{ - # use Test::NoWarnings, if available - $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; -} - -my $ver = Compress::Zlib::zlib_version(); -plan skip_all => "gzsetparams needs zlib 1.0.6 or better. You have $ver\n" - if ZLIB_VERNUM() < 0x1060 ; - -plan tests => 51 + $extra ; - -# Check zlib_version and ZLIB_VERSION are the same. -is Compress::Zlib::zlib_version, ZLIB_VERSION, - "ZLIB_VERSION matches Compress::Zlib::zlib_version" ; - -{ - # gzsetparams - title "Testing gzsetparams"; - - my $hello = "I am a HAL 9000 computer" x 2001 ; - my $len_hello = length $hello ; - my $goodbye = "Will I dream?" x 2010; - my $len_goodbye = length $goodbye; - - my ($input, $err, $answer, $X, $status, $Answer); - - my $lex = new LexFile my $name ; - ok my $x = gzopen($name, "wb"); - - $input .= $hello; - is $x->gzwrite($hello), $len_hello, "gzwrite returned $len_hello" ; - - # Error cases - eval { $x->gzsetparams() }; - like $@, mkErr('^Usage: Compress::Zlib::gzFile::gzsetparams\(file, level, strategy\)'); - - # Change both Level & Strategy - $status = $x->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ; - cmp_ok $status, '==', Z_OK, "status is Z_OK"; - - $input .= $goodbye; - is $x->gzwrite($goodbye), $len_goodbye, "gzwrite returned $len_goodbye" ; - - ok ! $x->gzclose, "closed" ; - - ok my $k = gzopen($name, "rb") ; - - # calling gzsetparams on reading is not allowed. - $status = $k->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ; - cmp_ok $status, '==', Z_STREAM_ERROR, "status is Z_STREAM_ERROR" ; - - my $len = length $input ; - my $uncompressed; - is $len, $k->gzread($uncompressed, $len) ; - - ok $uncompressed eq $input ; - ok $k->gzeof ; - ok ! $k->gzclose ; - ok $k->gzeof ; -} - - -foreach my $CompressClass ('IO::Compress::Gzip', - 'IO::Compress::Deflate', - 'IO::Compress::RawDeflate', - ) -{ - my $UncompressClass = getInverse($CompressClass); - - title "Testing $CompressClass"; - - - # deflateParams - - my $hello = "I am a HAL 9000 computer" x 2001 ; - my $len_hello = length $hello ; - my $goodbye = "Will I dream?" x 2010; - my $len_goodbye = length $goodbye; - - #my ($input, $err, $answer, $X, $status, $Answer); - my $compressed; - - ok my $x = new $CompressClass(\$compressed) ; - - my $input .= $hello; - is $x->write($hello), $len_hello ; - - # Change both Level & Strategy - ok $x->deflateParams(Z_BEST_SPEED, Z_HUFFMAN_ONLY); - - $input .= $goodbye; - is $x->write($goodbye), $len_goodbye ; - - ok $x->close ; - - ok my $k = new $UncompressClass(\$compressed); - - my $len = length $input ; - my $uncompressed; - is $k->read($uncompressed, $len), $len - or diag "$IO::Uncompress::Gunzip::GunzipError" ; - - ok $uncompressed eq $input ; - ok $k->eof ; - ok $k->close ; - ok $k->eof ; -} diff --git a/ext/Compress-Zlib/t/08encoding.t b/ext/Compress-Zlib/t/08encoding.t deleted file mode 100644 index f377609e57..0000000000 --- a/ext/Compress-Zlib/t/08encoding.t +++ /dev/null @@ -1,139 +0,0 @@ -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't' if -d 't'; - @INC = ("../lib", "lib/compress"); - } -} - -use lib qw(t t/compress); -use strict; -use warnings; -use bytes; - -use Test::More ; -use CompTestUtils; - -BEGIN -{ - plan skip_all => "Encode is not available" - if $] < 5.006 ; - - eval { require Encode; Encode->import(); }; - - plan skip_all => "Encode is not available" - if $@ ; - - # use Test::NoWarnings, if available - my $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - - plan tests => 29 + $extra ; - - use_ok('Compress::Zlib', 2); -} - - - - -# Check zlib_version and ZLIB_VERSION are the same. -is Compress::Zlib::zlib_version, ZLIB_VERSION, - "ZLIB_VERSION matches Compress::Zlib::zlib_version" ; - - -{ - title "memGzip" ; - # length of this string is 2 characters - my $s = "\x{df}\x{100}"; - - my $cs = Compress::Zlib::memGzip(Encode::encode_utf8($s)); - - # length stored at end of gzip file should be 4 - my ($crc, $len) = unpack ("VV", substr($cs, -8, 8)); - - is $len, 4, " length is 4"; -} - -{ - title "memGunzip when compressed gzip has been encoded" ; - my $s = "hello world" ; - - my $co = Compress::Zlib::memGzip($s); - is Compress::Zlib::memGunzip(my $x = $co), $s, " match uncompressed"; - - utf8::upgrade($co); - - my $un = Compress::Zlib::memGunzip($co); - ok $un, " got uncompressed"; - - is $un, $s, " uncompressed matched original"; -} - -{ - title "compress/uncompress"; - - my $s = "\x{df}\x{100}"; - my $s_copy = $s ; - - my $ces = compress(Encode::encode_utf8($s_copy)); - - ok $ces, " compressed ok" ; - - my $un = Encode::decode_utf8(uncompress($ces)); - is $un, $s, " decode_utf8 ok"; - - utf8::upgrade($ces); - $un = Encode::decode_utf8(uncompress($ces)); - is $un, $s, " decode_utf8 ok"; - -} - -{ - title "gzopen" ; - - my $s = "\x{df}\x{100}"; - my $byte_len = length( Encode::encode_utf8($s) ); - my ($uncomp) ; - - my $lex = new LexFile my $name ; - ok my $fil = gzopen($name, "wb"), " gzopen for write ok" ; - - is $fil->gzwrite(Encode::encode_utf8($s)), $byte_len, " wrote $byte_len bytes" ; - - ok ! $fil->gzclose, " gzclose ok" ; - - ok $fil = gzopen($name, "rb"), " gzopen for read ok" ; - - is $fil->gzread($uncomp), $byte_len, " read $byte_len bytes" ; - is length($uncomp), $byte_len, " uncompress is $byte_len bytes"; - - ok ! $fil->gzclose, "gzclose ok" ; - - is $s, Encode::decode_utf8($uncomp), " decode_utf8 ok" ; -} - -{ - title "Catch wide characters"; - - my $a = "a\xFF\x{100}"; - eval { Compress::Zlib::memGzip($a) }; - like($@, qr/Wide character in memGzip/, " wide characters in memGzip"); - - eval { Compress::Zlib::memGunzip($a) }; - like($@, qr/Wide character in memGunzip/, " wide characters in memGunzip"); - - eval { Compress::Zlib::compress($a) }; - like($@, qr/Wide character in compress/, " wide characters in compress"); - - eval { Compress::Zlib::uncompress($a) }; - like($@, qr/Wide character in uncompress/, " wide characters in uncompress"); - - my $lex = new LexFile my $name ; - ok my $fil = gzopen($name, "wb"), " gzopen for write ok" ; - - eval { $fil->gzwrite($a); } ; - like($@, qr/Wide character in gzwrite/, " wide characters in gzwrite"); - - ok ! $fil->gzclose, " gzclose ok" ; -} - diff --git a/ext/Compress-Zlib/t/14gzopen.t b/ext/Compress-Zlib/t/14gzopen.t deleted file mode 100644 index 85970d26b8..0000000000 --- a/ext/Compress-Zlib/t/14gzopen.t +++ /dev/null @@ -1,627 +0,0 @@ -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't' if -d 't'; - @INC = ("../lib", "lib/compress"); - } -} - -use lib qw(t t/compress); -use strict; -use warnings; -use bytes; - -use Test::More ; -use CompTestUtils; -use IO::File ; - -BEGIN { - # use Test::NoWarnings, if available - my $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - - plan tests => 250 + $extra ; - - use_ok('Compress::Zlib', 2) ; - use_ok('IO::Compress::Gzip::Constants') ; -} - - -my $hello = <gzerror(), 0, "gzerror() returned 0"; - -is $fil->gztell(), 0, "gztell returned 0"; -is $gzerrno, 0, 'gzerrno is 0'; - -is $fil->gzwrite($hello), $len ; -is $gzerrno, 0, 'gzerrno is 0'; - -is $fil->gztell(), $len, "gztell returned $len"; -is $gzerrno, 0, 'gzerrno is 0'; - -ok ! $fil->gzclose ; - -ok $fil = gzopen($name, "rb") ; - -ok ! $fil->gzeof() ; -is $gzerrno, 0, 'gzerrno is 0'; -is $fil->gztell(), 0; - -is $fil->gzread($uncomp), $len; - -is $fil->gztell(), $len; -ok $fil->gzeof() ; - -# gzread after eof bahavior - -my $xyz = "123" ; -is $fil->gzread($xyz), 0, "gzread returns 0 on eof" ; -is $xyz, "", "gzread on eof zaps the output buffer [Match 1,x behavior]" ; - -ok ! $fil->gzclose ; -ok $fil->gzeof() ; - - -1 while unlink $name ; - -ok $hello eq $uncomp ; - -# check that a number can be gzipped -my $number = 7603 ; -my $num_len = 4 ; - -ok $fil = gzopen($name, "wb") ; - -is $gzerrno, 0; - -is $fil->gzwrite($number), $num_len, "gzwrite returned $num_len" ; -is $gzerrno, 0, 'gzerrno is 0'; -ok ! $fil->gzflush(Z_FINISH) ; - -is $gzerrno, 0, 'gzerrno is 0'; - -ok ! $fil->gzclose ; - -cmp_ok $gzerrno, '==', 0; - -ok $fil = gzopen($name, "rb") ; - -ok (($x = $fil->gzread($uncomp)) == $num_len) ; - -ok $fil->gzerror() == 0 || $fil->gzerror() == Z_STREAM_END; -ok $gzerrno == 0 || $gzerrno == Z_STREAM_END; -ok $fil->gzeof() ; - -ok ! $fil->gzclose ; -ok $fil->gzeof() ; - -ok $gzerrno == 0 - or print "# gzerrno is $gzerrno\n" ; - -1 while unlink $name ; - -ok $number == $uncomp ; -ok $number eq $uncomp ; - - -# now a bigger gzip test - -my $text = 'text' ; -my $file = "$text.gz" ; - -ok my $f = gzopen($file, "wb") ; - -# generate a long random string -my $contents = '' ; -foreach (1 .. 5000) - { $contents .= chr int rand 256 } - -$len = length $contents ; - -ok $f->gzwrite($contents) == $len ; - -ok ! $f->gzclose ; - -ok $f = gzopen($file, "rb") ; - -ok ! $f->gzeof() ; - -my $uncompressed ; -is $f->gzread($uncompressed, $len), $len ; - -ok $contents eq $uncompressed - - or print "# Length orig $len" . - ", Length uncompressed " . length($uncompressed) . "\n" ; - -ok $f->gzeof() ; -ok ! $f->gzclose ; - -1 while unlink($file) ; - -# gzip - readline tests -# ====================== - -# first create a small gzipped text file -$name = "test.gz" ; -my @text = (<gzwrite($text) == length $text ; -ok ! $fil->gzclose ; - -# now try to read it back in -ok $fil = gzopen($name, "rb") ; -ok ! $fil->gzeof() ; -my $line = ''; -for my $i (0 .. @text -2) -{ - ok $fil->gzreadline($line) > 0; - is $line, $text[$i] ; - ok ! $fil->gzeof() ; -} - -# now read the last line -ok $fil->gzreadline($line) > 0; -is $line, $text[-1] ; -ok $fil->gzeof() ; - -# read past the eof -is $fil->gzreadline($line), 0; - -ok $fil->gzeof() ; -ok ! $fil->gzclose ; -ok $fil->gzeof() ; -1 while unlink($name) ; - -# a text file with a very long line (bigger than the internal buffer) -my $line1 = ("abcdefghijklmnopq" x 2000) . "\n" ; -my $line2 = "second line\n" ; -$text = $line1 . $line2 ; -ok $fil = gzopen($name, "wb") ; -ok $fil->gzwrite($text) == length $text ; -ok ! $fil->gzclose ; - -# now try to read it back in -ok $fil = gzopen($name, "rb") ; -ok ! $fil->gzeof() ; -my $i = 0 ; -my @got = (); -while ($fil->gzreadline($line) > 0) { - $got[$i] = $line ; - ++ $i ; -} -is $i, 2 ; -is $got[0], $line1 ; -is $got[1], $line2 ; - -ok $fil->gzeof() ; -ok ! $fil->gzclose ; -ok $fil->gzeof() ; - -1 while unlink $name ; - -# a text file which is not termined by an EOL - -$line1 = "hello hello, I'm back again\n" ; -$line2 = "there is no end in sight" ; - -$text = $line1 . $line2 ; -ok $fil = gzopen($name, "wb") ; -ok $fil->gzwrite($text) == length $text ; -ok ! $fil->gzclose ; - -# now try to read it back in -ok $fil = gzopen($name, "rb") ; -@got = () ; $i = 0 ; -while ($fil->gzreadline($line) > 0) { - $got[$i] = $line ; - ++ $i ; -} -is $i, 2 ; -is $got[0], $line1 ; -is $got[1], $line2 ; - -ok $fil->gzeof() ; -ok ! $fil->gzclose ; - -1 while unlink $name ; - -{ - - title 'mix gzread and gzreadline'; - - # case 1: read a line, then a block. The block is - # smaller than the internal block used by - # gzreadline - my $lex = new LexFile my $name ; - $line1 = "hello hello, I'm back again\n" ; - $line2 = "abc" x 200 ; - my $line3 = "def" x 200 ; - - $text = $line1 . $line2 . $line3 ; - my $fil; - ok $fil = gzopen($name, "wb"), ' gzopen for write ok' ; - is $fil->gzwrite($text), length $text, ' gzwrite ok' ; - is $fil->gztell(), length $text, ' gztell ok' ; - ok ! $fil->gzclose, ' gzclose ok' ; - - # now try to read it back in - ok $fil = gzopen($name, "rb"), ' gzopen for read ok' ; - ok ! $fil->gzeof(), ' !gzeof' ; - cmp_ok $fil->gzreadline($line), '>', 0, ' gzreadline' ; - is $fil->gztell(), length $line1, ' gztell ok' ; - ok ! $fil->gzeof(), ' !gzeof' ; - is $line, $line1, ' got expected line' ; - cmp_ok $fil->gzread($line, length $line2), '>', 0, ' gzread ok' ; - is $fil->gztell(), length($line1)+length($line2), ' gztell ok' ; - ok ! $fil->gzeof(), ' !gzeof' ; - is $line, $line2, ' read expected block' ; - cmp_ok $fil->gzread($line, length $line3), '>', 0, ' gzread ok' ; - is $fil->gztell(), length($text), ' gztell ok' ; - ok $fil->gzeof(), ' !gzeof' ; - is $line, $line3, ' read expected block' ; - ok ! $fil->gzclose, ' gzclose' ; -} - -{ - title "Pass gzopen a filehandle - use IO::File" ; - - my $lex = new LexFile my $name ; - - my $hello = "hello" ; - my $len = length $hello ; - - my $f = new IO::File ">$name" ; - ok $f; - - my $fil; - ok $fil = gzopen($f, "wb") ; - - ok $fil->gzwrite($hello) == $len ; - - ok ! $fil->gzclose ; - - $f = new IO::File "<$name" ; - ok $fil = gzopen($name, "rb") ; - - my $uncmomp; - ok (($x = $fil->gzread($uncomp)) == $len) - or print "# length $x, expected $len\n" ; - - ok $fil->gzeof() ; - ok ! $fil->gzclose ; - ok $fil->gzeof() ; - - is $uncomp, $hello, "got expected output" ; -} - - -{ - title "Pass gzopen a filehandle - use open" ; - - my $lex = new LexFile my $name ; - - my $hello = "hello" ; - my $len = length $hello ; - - open F, ">$name" ; - - my $fil; - ok $fil = gzopen(*F, "wb") ; - - is $fil->gzwrite($hello), $len ; - - ok ! $fil->gzclose ; - - open F, "<$name" ; - ok $fil = gzopen(*F, "rb") ; - - my $uncmomp; - $x = $fil->gzread($uncomp); - is $x, $len ; - - ok $fil->gzeof() ; - ok ! $fil->gzclose ; - ok $fil->gzeof() ; - - is $uncomp, $hello ; - - -} - -foreach my $stdio ( ['-', '-'], [*STDIN, *STDOUT]) -{ - my $stdin = $stdio->[0]; - my $stdout = $stdio->[1]; - - title "Pass gzopen a filehandle - use $stdin" ; - - my $lex = new LexFile my $name ; - - my $hello = "hello" ; - my $len = length $hello ; - - ok open(SAVEOUT, ">&STDOUT"), " save STDOUT"; - my $dummy = fileno SAVEOUT; - ok open(STDOUT, ">$name"), " redirect STDOUT" ; - - my $status = 0 ; - - my $fil = gzopen($stdout, "wb") ; - - $status = $fil && - ($fil->gzwrite($hello) == $len) && - ($fil->gzclose == 0) ; - - open(STDOUT, ">&SAVEOUT"); - - ok $status, " wrote to stdout"; - - open(SAVEIN, "<&STDIN"); - ok open(STDIN, "<$name"), " redirect STDIN"; - $dummy = fileno SAVEIN; - - ok $fil = gzopen($stdin, "rb") ; - - my $uncmomp; - ok (($x = $fil->gzread($uncomp)) == $len) - or print "# length $x, expected $len\n" ; - - ok $fil->gzeof() ; - ok ! $fil->gzclose ; - ok $fil->gzeof() ; - - open(STDIN, "<&SAVEIN"); - - is $uncomp, $hello ; - - -} - -{ - title 'test parameters for gzopen'; - my $lex = new LexFile my $name ; - - my $fil; - - # missing parameters - eval ' $fil = gzopen() ' ; - like $@, mkEvalErr('Not enough arguments for Compress::Zlib::gzopen'), - ' gzopen with missing mode fails' ; - - # unknown parameters - $fil = gzopen($name, "xy") ; - ok ! defined $fil, ' gzopen with unknown mode fails' ; - - $fil = gzopen($name, "ab") ; - ok $fil, ' gzopen with mode "ab" is ok' ; - - $fil = gzopen($name, "wb6") ; - ok $fil, ' gzopen with mode "wb6" is ok' ; - - $fil = gzopen($name, "wbf") ; - ok $fil, ' gzopen with mode "wbf" is ok' ; - - $fil = gzopen($name, "wbh") ; - ok $fil, ' gzopen with mode "wbh" is ok' ; -} - -{ - title 'Read operations when opened for writing'; - - my $lex = new LexFile my $name ; - my $fil; - ok $fil = gzopen($name, "wb"), ' gzopen for writing' ; - ok !$fil->gzeof(), ' !eof'; ; - is $fil->gzread(), Z_STREAM_ERROR, " gzread returns Z_STREAM_ERROR" ; - ok ! $fil->gzclose, " gzclose ok" ; -} - -{ - title 'write operations when opened for reading'; - - my $lex = new LexFile my $name ; - my $test = "hello" ; - my $fil; - ok $fil = gzopen($name, "wb"), " gzopen for writing" ; - is $fil->gzwrite($text), length $text, " gzwrite ok" ; - ok ! $fil->gzclose, " gzclose ok" ; - - ok $fil = gzopen($name, "rb"), " gzopen for reading" ; - is $fil->gzwrite(), Z_STREAM_ERROR, " gzwrite returns Z_STREAM_ERROR" ; -} - -{ - title 'read/write a non-readable/writable file'; - - SKIP: - { - my $lex = new LexFile my $name ; - writeFile($name, "abc"); - chmod 0444, $name ; - - skip "Cannot create non-writable file", 3 - if -w $name ; - - ok ! -w $name, " input file not writable"; - - my $fil = gzopen($name, "wb") ; - ok !$fil, " gzopen returns undef" ; - ok $gzerrno, " gzerrno ok" or - diag " gzerrno $gzerrno\n"; - - chmod 0777, $name ; - } - - SKIP: - { - my $lex = new LexFile my $name ; - skip "Cannot create non-readable file", 3 - if $^O eq 'cygwin'; - - writeFile($name, "abc"); - chmod 0222, $name ; - - skip "Cannot create non-readable file", 3 - if -r $name ; - - ok ! -r $name, " input file not readable"; - $gzerrno = 0; - $fil = gzopen($name, "rb") ; - ok !$fil, " gzopen returns undef" ; - ok $gzerrno, " gzerrno ok"; - chmod 0777, $name ; - } - -} - -{ - title "gzseek" ; - - my $buff ; - my $lex = new LexFile my $name ; - - my $first = "beginning" ; - my $last = "the end" ; - my $iow = gzopen($name, "w"); - $iow->gzwrite($first) ; - ok $iow->gzseek(5, SEEK_CUR) ; - is $iow->gztell(), length($first)+5; - ok $iow->gzseek(0, SEEK_CUR) ; - is $iow->gztell(), length($first)+5; - ok $iow->gzseek(length($first)+10, SEEK_SET) ; - is $iow->gztell(), length($first)+10; - - $iow->gzwrite($last) ; - $iow->gzclose ; - - ok GZreadFile($name) eq $first . "\x00" x 10 . $last ; - - my $io = gzopen($name, "r"); - ok $io->gzseek(length($first), SEEK_CUR) ; - ok ! $io->gzeof; - is $io->gztell(), length($first); - - ok $io->gzread($buff, 5) ; - is $buff, "\x00" x 5 ; - is $io->gztell(), length($first) + 5; - - is $io->gzread($buff, 0), 0 ; - #is $buff, "\x00" x 5 ; - is $io->gztell(), length($first) + 5; - - ok $io->gzseek(0, SEEK_CUR) ; - my $here = $io->gztell() ; - is $here, length($first)+5; - - ok $io->gzseek($here+5, SEEK_SET) ; - is $io->gztell(), $here+5 ; - ok $io->gzread($buff, 100) ; - ok $buff eq $last ; - ok $io->gzeof; -} - -{ - # seek error cases - my $lex = new LexFile my $name ; - - my $a = gzopen($name, "w"); - - ok ! $a->gzerror() - or print "# gzerrno is $Compress::Zlib::gzerrno \n" ; - eval { $a->gzseek(-1, 10) ; }; - like $@, mkErr("gzseek: unknown value, 10, for whence parameter"); - - eval { $a->gzseek(-1, SEEK_END) ; }; - like $@, mkErr("gzseek: cannot seek backwards"); - - $a->gzwrite("fred"); - $a->gzclose ; - - - my $u = gzopen($name, "r"); - - eval { $u->gzseek(-1, 10) ; }; - like $@, mkErr("gzseek: unknown value, 10, for whence parameter"); - - eval { $u->gzseek(-1, SEEK_END) ; }; - like $@, mkErr("gzseek: SEEK_END not allowed"); - - eval { $u->gzseek(-1, SEEK_CUR) ; }; - like $@, mkErr("gzseek: cannot seek backwards"); -} - -{ - title "gzread ver 1.x compat -- the output buffer is always zapped."; - my $lex = new LexFile my $name ; - - my $a = gzopen($name, "w"); - $a->gzwrite("fred"); - $a->gzclose ; - - my $u = gzopen($name, "r"); - - my $buf1 ; - is $u->gzread($buf1, 0), 0, " gzread returns 0"; - ok defined $buf1, " output buffer defined"; - is $buf1, "", " output buffer empty string"; - - my $buf2 = "qwerty"; - is $u->gzread($buf2, 0), 0, " gzread returns 0"; - ok defined $buf2, " output buffer defined"; - is $buf2, "", " output buffer empty string"; -} - -{ - title 'gzreadline does not support $/'; - - my $lex = new LexFile my $name ; - - my $a = gzopen($name, "w"); - my $text = "fred\n"; - my $len = length $text; - $a->gzwrite($text); - $a->gzwrite("\n\n"); - $a->gzclose ; - - for my $delim ( undef, "", 0, 1, "abc", $text, "\n\n", "\n" ) - { - local $/ = $delim; - my $u = gzopen($name, "r"); - my $line; - is $u->gzreadline($line), length $text, " read $len bytes"; - is $line, $text, " got expected line"; - ok ! $u->gzclose, " closed" ; - is $/, $delim, ' $/ unchanged by gzreadline'; - } -} diff --git a/ext/IO-Compress/Changes b/ext/IO-Compress/Changes new file mode 100644 index 0000000000..8e392c9931 --- /dev/null +++ b/ext/IO-Compress/Changes @@ -0,0 +1,794 @@ +CHANGES +------- + + 2.017 22 February 2009 + + * TODO - mention LimitOutput + + * Merged IO-Compress-Base, IO-Compress-Bzip2, IO-Compress-Zlib & + Compress-Zlib into IO-Compress. + + * IO::Compress::Base & IO::Uncompress::Base + Downgraded some croaks in the constructors to just set $! (by letting + the code attempt to open a file and fail). + This makes the behavior more consistent to a standard open. + [RT #42657] + + * IO::Uncompress::Base + Doing a seek with MultiStream could drop some of the uncompressed + data. Fixed. + + * IO::Compress::Zip + - Fixed problem with the uncompressed & uncompressed fields when + zip64 is enabled. They were set to 0x0000FFFF instead of + 0xFFFFFFFF. Also the ZIP64 extra field was 4 bytes short. + Problem spotted by Dino Chiesa. + + * Compress::Zlib + - Documented Compress::Zlib::zlib_version() + + + 2.015 3 September 2008 + + * Makefile.PL + Backout changes made in 2.014 + + 2.014 2 September 2008 + + * Makefile.PL + Updated to check for indirect dependencies. + + 2.013 18 July 2008 + + * IO::Compress::Base + - Allow IO::Compress::Base::Parameters::parse to accept an + IO::Compress::Base::Parameters object. + + 2.012 15 July 2008 + + * IO::Compress::Base + - Silenced an uninitialised value warning when reading a line + at a time from a zip file where the content uses ZIP_CM_STORE. + [Problem spotted & fixed by Jeff Holt] + + * IO::Compress::Base & IO::Uncompress::Base + - local-ise $!, $? et al in the DESTROY methods. + + 2.011 17 May 2008 + + * IO::Compress::Base + - Fixed problem that prevented the creation of a zip file that + contained more than one compression method. + + * IO::Compress::Base::Common + - The private Validator class in this module clashes with another + CPAN module. Moved Validator into the IO::Compress::Base::Common + namespace. + [RT #35954] + + * IO::Uncompress::Unzip + - Print an error message if the zip file contains a + member compressed with bzip2 and IO::Uncompress::Bunzip2 is + not available. + - Could not cope with mixed compression zip files. For example a + zip file that contains both STORED and DEFLATED content. + [RT #35573] + + 2.010 5 May 2008 + + * Fixed problem that meant Perl 5.10 could not upgrade this module. + [RT #35342 & 35341] + + 2.009 20 April 2008 + + * Removed the alpha status from File::GlobMapper + + * IO::Compress::Base + When writing output never output a zero length buffer. + Done to improve interoperability with other tied filenandle + modules. + + * Changed IO::Uncompress::Base to not use the offset parameter of + the read method when reading from a filehandle. + + The object returned from Net::FTP::retr implements a non-standard + read method. The third parameter is used for a timeout value + rather than an offset. + [rt.cpan#33231] + + * Changed IO::Uncompress::Base to not use the eof method when + reading from a filehandle. + + The object returned from Net::FTP::retr implements both the read + method and the eof method. Unfortunately the implementation of + the read method uses non-buffered IO (by using sysread) while + the eof method uses buffered IO. Mixing buffered and non-buffered + IO results in data corruption. + + * IO::Compress::Zip + + - Added exUnix2 option to allow storing of UID & GID. + - When running on a Unix derivative the ExtAttr option now defaults + to the equivalent of 0666. For all other systems the default + remains 0. + + * Compress::Zlib + - Minor documentation issue with flush. + [rt.cpan.org #31446] + + + 2.008 2 November 2007 + + * Minor documentation changes in README + + * t/compress/truncate.pl + EBCDIC Cleanup. + + * IO::Compress::Gzip::Constants.pm + Tidied up the character classes used to defined invalid + FNAME & FCOMMENT fields for EBCDIC. + + * Compress::Zlib + lib/Compress/Zlib.pm -- 1.x Backward Compatability issues + gzclose - documented return value was wrong, should be 0 for ok. + gzflush - return value didn't match 1.x, should return 0 if ok. + [rt.cpan.org #29215] and Debian bug #440943 http://bugs.debian.org/440943 + + 2.006 1 September 20007 + + * Makefile.PL + Added INSTALLDIRS directive to install as a core module when built + on a perl >= 5.9. + + * IO::Uncompress::RawDeflate + + - Fixed export problem - "$RawDeflateError" and "rawdeflate" were + not being exported with ":all". + + * Compress::Zlib + - t/03zlib-v1.t + Fixed crc32 and adler32 tests in to remove ascii assumption. + + - lib/Compress/Zlib.pm + Make gzreadline not support $/, just like in Compress::Zlib 1.x + Folk who want $/ with readline support can get it in + IO::Uncompress::Gunzip. [rt.cpan.org #28663] and + Debian bug #435656 http://bugs.debian.org/435656 + + + 2.005 18 June 2007 + + * Stephen Turner reported a problem when using IO::Uncompress::Gunzip + with XML::Parser. Turns out there were two issues. + + Firstly an IO::Uncompress object isn't an IO::Handle. It is now. + + Secondly the implementation of "read" wasn't honouring this + + SCALAR will be grown or shrunk to the length actually read. + + In particular it didn't do the right thing on EOF. + This has been fixed. + + * IO::Compress::Gzip & IO::Uncompress::Gunzip + + - RFC1952 says that the FNAME & FCOMMENT header fields must be ISO + 8859-1 (LATIN-1) characters. The code can optionally police this. + Added a fix for this logic when running on EBCDIC. + + * Compress::Zlib + Added info about removing Compress::Zlib version 1, before + installing version 2. + + 2.004 3 March 2007 + + * Made seek less wasteful of memory. + + * IO::Compress::Zip + + - Added Zip64 documentation. + + - Fixed extended timestamp. + Creation time isn't available in Unix so only store the + modification time and the last access time in the extended field. + + - Fixed file mode. + + - Added ExtAttr option to control the value of the "external file + attributes" field in the central directory. + + - Added Unix2 extended attribute ("Ux"). + This stores the UID & GID. + + * IO::Compress::Gzip + + - Fixed 050interop-gzip.t for Windows + + * IO::Compress::Bzip2 + + - Fixed 050interop-bzip2.t for Windows + + * Compress::Zlib + + - rewrote memGzip using IO::Compress::Gzip::gzip + + 2.003 2 January 2007 + + * Added explicit version checking + + 2.002 29 December 2006 + + * Documentation updates. + + * Added IO::Handle to the ISA test in isaFilehandle + + * Add an explicit use_ok test for Scalar::Util in the test harness. + The error message reported by 01misc implied the problem was + somewhere else. + Also explictly check that 'dualvar' is available. + + * Compress::Zlib + - Fix append mode with gzopen. + rt-cpan.org 24041 + + - Allow gzopen to read from and write to a scalar reference. + + 2.001 1 November 2006 + + * Remove beta status. + + 2.000_14 26 October 2006 + + * IO::Uncompress::Base + Added support for $/ in record mode + + * IO::Uncompress::Base + The readline interface was substantially slower than the 1.x + equivalent. This has now been sorted. + Thanks to Andreas J. Koenig for spotting the problem. + + * IO::Uncompress::AnyUncompress + Added IO::Uncompress::Lzf to the list of supported uncompresors. + + * IO::Uncompress::Base + Added TrailingData to one-shot interface. + + * IO::Uncompress::AnyUncompress + Remove raw-deflate (RFC1951) from the default list of compressors + to check. + It can still be included if the new RawInflate parameter is + supplied. + This change was made because the only way to tell if content is + raw-deflate is to attempt to uncompress it - a few false positives + have popped up recently, which suggests that auto-detecting raw + deflate is far from perfect. + The equivalent change has been made to IO::Uncompress::AnyInflate. + [Core patch #28445] + + * Don't check that filehandles are writable. It would seem that + "-w *STDOUT" on windows returns false. + [Core Patch #28415] + + * IO::Uncompress::Deflate + Beefed up the magic signature check. Means less false positives + when auto-detecting the compression type. + + * IO::Uncompress::UnZip + Tighten up the zip64 extra field processing to cope with the case + wheere only some of the local header fields are superceeded. + + * IO::Uncompress::AnyInflate + Remove raw-deflate (RFC 1951) from the default list of compressors + to check. + It can still be included if the new RawInflate parameter is + supplied. + This change was made because the only way to tell if content is + raw-deflate is to attempt to uncompress it - a few false positives + have popped up recently, which suggests that auto-detecting raw + deflate is far from perfect. + The equivalent change has been made to IO::Uncompress::AnyUncompress. + [Core patch #28445] + + 2.000_13 20 June 2006 + + * Store compress & uncompressed sizes as 64-bit. + + * For one-shot uncompression, like this + + unzip "some.zip" => \@a, MultiStream => 1; + + Push each uncompressed stream from "some.zip" onto @a. + + * Added IO::Compress::Base::FilterEnvelope + + * Added IO::Uncompress::Base::nextStream + + * The '-' filehandle now maps to either *STDIN or *STDOUT. + This keeps mod_perl happier. Was using these before + + new IO::File("<-") + new IO::File(">-") + + * Preliminary support for reading zip files with zip64 members. + + 2.000_12 3 May 2006 + + * Moved the code for creating and parsing the gzip extra field into + IO::Compress::Zlib::Extra.pm so that IO::Compress::Zip & + IO::Uncompress::Unzip can use it as well. + + * Added ExtraFieldLocal & ExtraFieldCentral options to IO::Compress::Zip. + These allow the creation of user-defined extra fields in the local + and central headers, just like the ExtraField option in + IO::Compress::Gzip. + + * Moved the zip constants into IO::Compress::Zip::Constants + + * Added exTime option to IO::Compress::Zip. + This allows creation of the extended timestamp extra field. + + * Added Minimal option to IO::Compress::Zip. + This disables the creation of all extended fields. + + * Added TextFlag option to IO::Compress::Zip. + + * Documented Comment and ZipComment options in IO::Compress::Zip. + + * Compress::Zlib + Fixed gzread to zap the output buffer to an empty string when zero + bytes are requested. This matches the behaviour of C::Z 1.x + + 2.000_11 10 April 2006 + + * Transparent + InputLength made more robust where input data is not + compressed. + + * Updated Documentation for zip modules. + + * Changed IO::Compress::Zip 'Store' option to 'Method' and added + symbolic constants ZIP_CM_STORE, ZIP_CM_DEFLATE and ZIP_CM_BZIP2 to + allow the compression method to be picked by the user. + + * Added support to allow bzip2 compressed data to be written/read + with IO::Compress::Zip and IO::Uncompress::Unzip. + + * Beefed up 050interop-gzip.t to check that the external gzip command + works as expected before starting the tests. This means that + this test harness will just be skipped on problematic systems. + + * Merged core patch 27565 from Steve Peters. This works around a + problem with gzip on OpenBSD where it doesn't seem to like + compressing files < 10 bytes long. + + * Beefed up 050interop-bzip2.t to check that the external bzip2 command + works as expected before starting the tests. This means that + this test harness will just be skipped on problematic systems. + + 2.000_10 13 March 2006 + + * AnyUncompress doesn't assume that IO-Compress-Zlib is installed any + more. + + * Documentation updates. + + * Compress::Zlib + Changed gzread so that its behaviour matches C::Z::gzread 1.x if it + is called after eof. In this case it will write an empty string + into the output parameter. This change is solely for backward + compatability reasons. + + 2.000_09 3 March 2006 + + * Released to CPAN. + + 2.000_08 2 March 2006 + + * Split IO::Compress::Base into its own distribution. + + * Split IO::Compress::Bzip2 into its own distribution. + + * Added opened, autoflush and input_line_number. + + * Beefed up support for $. + + * Split IO::Compress::Zlib into its own distribution. + + * Beefed up support for zip/unzip + + * Breakout zlib specific code into separate modules. + + * Limited support for reading/writing zip files + + 2.000_06 5 October 2005 + + * Added eof parameter to Compress::Zlib::inflate method. + + * Fixed issue with 64-bit + + 2.000_05 4 October 2005 + + * Renamed IO::* to IO::Compress::* & IO::Uncompress::* + + 2.000_04 23 September 2005 + + * Fixed some more non-portable test that were failing on VMS. + + * fixed problem where error messages in the oneshot interface were + getting lost. + + 2.000_03 12 September 2005 + + * Fixed some non-portable test that were failing on VMS. + + * Fixed export of zlib constants from the IO::* classes + + 2.000_02 6 September 2005 + + * Split Append mode into Append and Merge + + * Fixed typos in the documentation. + + * Added pod/FAQ.pod + + * Added libscan to Makefile.PL + + * Added InputLength for IO::Gunzip et al + + 2.000_01 22 August 2005 + + * Fixed VERSION in Compress::Gzip::Constants + + * Removed Compress::Gzip::Info from the distribution. + + 2.000_00 21 August 2005 + + * First Beta relase of Compress::zlib rewrite. + +Compress-Zlib version 1 Changes + + 1.38 - 6 September 2005 + + * Integrate core change 25304 -- Symbian Update + + * Added libscan to Makefile.PL + + 1.37 - 12 August 2005 + + * Change to t/03examples.t for VMS from Abe Timmerman + + 1.36 - 3 August 2005 + + * Renamed zlib-src-1.2.3 to zlib-src to help VMS + + * Fixed Makefile.PL for VMS + + * Fixed t/03examples.t for VMS + + * Added a couple of notes about incompatibility with Unix compress. + + 1.35 - 16 July 2005 + + * Updated zlib source to 1.2.3 + + * Fixed problem with where two calls to gzclose would hang the debugger. + See https://rt.cpan.org/Ticket/Display.html?id=13789 + + * Added code from Alexey Tourbin to use XSLoader when available, + and DynaLoader otherwise. + + * Documented that the compress & uncompress functions were not + the same as the Unix utilities of the same name. + + * Fixed 05gzsetp -- it left a temp file hanging around. + + * Integrate core change 24787 - SvUPGRADE returns void in blead + + * Integrate core change 24788 - Makefile.PL adjustments for the core + + + 1.34 - 30 January 2005 + + * Fixed typo in the README + + * Fixed examples.t on Win32 where paths have embedded whitespace. + + * Fix for Cygwin and core integration from Jos I. Boumans + + * Upgrade zlib source to 1.2.2 + + 1.33 - 14 January 2004 + + * Reworked Makefile.PL to avoid creating a private copy of zlib. + This both simplifies the build, plus it makes life easier for VMS. + + * Patches for Makefile.PL to get it to work on VMS supplied by + Craig A. Berry. + + * memGunzip has very slow on FreeBSD. Turns out to be down to + the way realloc works on FreeBSD. Changed both inflate & deflate + to use exponentially increasing buffer sizes when they need to + realloc. Thanks to Peter Jeremy for the lowdown on FreeBSD + memory allocation. + + 1.32 - 26 November 2003 + + * Steve Hay reported a problem on rt.cpan.org with Windows and + MSCV++ 6.0 where the source from the zlib directory was getting + installed with the rest of the module. + https://rt.cpan.org/Ticket/Display.html?id=1741 + + This has been fixed by renaming the "zlib" directory to "zlib-src" + thus avoiding a conflict with the name of this Perl module. + + * Fixed a bug in the inflate method where the input buffer is an + lvalue (via substr). Problem & solution reported by Salvador Fandiqo. + + * Tightened up the logic in Makefile.PL when BUILD_ZLIB is + True. Issue spotted by Ralf S. Engelschall. + + 1.31 - 29 October 2003 + + * Reinstated the creation of .bak files - $^I seems to need a + backup file on Windows. For OpenVMS, the extenstion _bak is used. + + 1.30 - 28 October 2003 + + * Bundled a sub-set of the zlib source with the module and changed + the default make behaviour to build with the included zlib source. + The previous behaviour of using a pre-built zlib library is + still available for those that want it. + + * Added prototypes to the subs in Zlib.pm that didn't already have + them. Patch from Ed Avis. + + * No .bak files are created by Makefile.PL any more - this keep + distclean much happier. Patch suggested by Ed Avis. + This also fixes a similar problem reported by Dr. Martin Zinser + on OpenVMS. + + * Documentation for some of the gz functions updated. + + * Format strings modified in DispStream to keep OpenVMS happy. + Problem reported by Dr. Martin Zinser. + + + 1.22 - 17 June 2003 + + * Makefile.PL now displays a warning about not installing + Compress::Zlib via the CPAN shell. + + * Fix to allow intermingling of gzread & gzreadline - patch + supplied by Doug Perham. + + * memGunzip will silently now work if the gzip trailer is + missing. Some HTTP Origin Servers seem to leave it out. + + 1.21 - 28 April 2003 + + * Tests 148 & 150 from t/02zlib.t were failing on redhat 9. + + * Added a few words about the problems with Mac OS X to the README file. + + 1.20 - 4 April 2003 + + * Fixed bug in gzopen where $gzerrno wasn't being set correctly. + The symptom was $gzerrno was set to Z_MEM_ERROR although the file + was opened ok. If gzopen failed, $gzerrno was being set correctly. + This problem wasn't spotted before because the typical test + to determine whether gzopen passed or failed was to check its + return value. + + 1.19 - 31 October 2002 + + * fixed a problem with t/02zlib.t that was failing with redhat 8. + + 1.18 - 24 October 2002 + + * fixed a Win32 problem in t/02zlib.t by changing sysread to read. + + * zlib 1.0.5 & older doesn't have gzsetparams & gzeof. Added a new + variable to config.in to flag an old version of zlib. Split + out the tests for gzsetparams into t/05gzsetp.t + + 1.17 - 23 May 2002 + + * Moved the test to check the versions of libz & zlib.h into a separate + file and added troubleshooting notes to README. + + * In gzopen, only attempt to call "tell" for normal files. + + * Fixed to work in taint mode. + + * Broke changes out of README into Changes file. + + * Replaced internal use of Z_PARTIAL_FLUSH symbol with Z_SYNC_FLUSH. + zlib.h says /* will be removed, use Z_SYNC_FLUSH instead */ + + 1.16 - 13 December 2001 + + * Fixed bug in Makefile.PL that stopped "perl Makefile.PL PREFIX=..." + working. + + 1.15 - 4th December 2001 + + * Changes a few types to get the module to build on 64-bit Solaris + + * Changed the up/downgrade logic to default to the older constructs, and + to only call a downgrade if specifically requested. Some older versions + of Perl were having problems with the in-place edit. + + * added the new XS constant code. + + 1.14 - 27th August 2001 + + * Memory overwrite bug fixed in "inflate". Kudos to Rob Simons for + reporting the bug and to Anton Berezin for fixing it for me. + + 1.13 - 31st June 2001 + + * Make sure config.in is consistant when released. + + 1.12 - 28th April 2001 + + * Modified Makefile.PL to only enable the warnings pragma if + using perl 5.6.1 or better. + + 1.11 - 17th February 2001 + + * Added logic in Makefile.PL to toggle between using $^W and + the warnings pragma in the module. + + * The module, the examples & the test harness are now all strict + & warnings clean. + + 1.10 - 5th February 2001 + + * fixed a bug in memGunzip. Used Z_ERR instead of Z_DATA_ERROR. + + 1.09 - 15th January 2001 + + * Silenced a few compiler warnings. + + * Updated zlib home site in README & Zlib.pm to www.info-zip.org + + * Minor typo in Zlib.pm - a link used AUTHORS instead of AUTHOR + -- spotted by Frank Martini. + + * Mention Archive::Zip + + * added memGunzip. This is largely based on code provided by Jim Leonard. + + * $deflate->flush can now take an optional parameter. Valid + values are Z_NO_FLUSH, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH + and Z_FINISH. The default is Z_FINISH. + + 1.08 - 6 Jan 2000 + + * uncompress was clobbering its input parameter. Now it doesn't. + This bug was spotted by Deven T. Corzine. + + * If a variable that only ever contained a number was given + to compress or deflate, it would not be compressed properly. Now + it will be coerced to a string and then compressed. This bug + was spotted by Deven T. Corzine. + + 1.07 - 27 Nov 1999 + + * ANSI-ified the static functions in Zlib.xs + + * Added the ability to build zlib along with the module. + This feature is 90% based on a Makefile provided by Gurusamy + Sarathy. + + 1.06 - 20 Sep 1999 + + * Fixed a nasty problem where inflate could truncate the data + returned. Thanks to Douglas Thomson + for both spotting the problem and fixing the bug. + + * Added a note about the undocumented features in zlib that are + required when accessing zip files. + + * gzclose will now get called automatically when the gzip object is + destroyed. + + 1.05 - 3 June 1999 + + * Previous release used newSVpvn, which doesn't exist in 5.004_04 + or earlier. Changed to use newSVpv instead. + + * The module needs Perl 5.004 or better, so updated the version + checking in Zlib.pm and Makefile.PL + + 1.04 - 27 May 1999 + + * Bug 19990527.001: compress(undef) core dumps -- Fixed. + + 1.03 - 17 Mar 1999 + + * Updated to use the new PL_ symbols. + Means the module can be built with Perl 5.005_5* + + 1.02 - 31 Jan 1999 + + * The return codes for gzread, gzreadline and gzwrite were + documented incorrectly as returning a status code. + + * The test harness was missing a "gzclose". This caused problem + showed up on an amiga. Thanks to Erik van Roode for reporting + this one. + + * Patched zlib.t for OS/2. Thanks to Ilya Zakharevich for the patch. + + 1.01 - 23 Nov 1997 + + * A number of fixes to the test suite and the example scripts to + allow them to work under win32. All courtesy of Gurusamy + Sarathy. + + 1.00 - 14 Nov 1997 + + * Fixed crc32 & adler32. They were very broken. + + * The following functions can now take a scalar reference in + place of a scalar for their buffer parameters: + + compress + uncompress + deflate + inflate + crc32 + adler32 + + This should mean applications that make use of the module don't + have to copy large buffers around. + + + * Normally the inflate method consumes I of the input buffer + before returning. The exception to this is when inflate detects + the end of the stream (Z_STREAM_END). In this case the input + buffer need not be completely consumed. To allow processing of + file formats that embed a deflation stream (e.g. zip, gzip), + the inflate method now sets the buffer parameter to be what + remains after inflation. + + When the return status is Z_STREAM_END, it will be what remains + of the buffer (if any) after deflation. When the status is Z_OK + it will be an empty string. + + This change means that the buffer parameter must be a lvalue. + + * Fixed crc32 and adler32. They were both very broken. + + * Added the Compress::Zlib::memGzip function. + + 0.5 - Confirmed that no changes were necessary for zlib 1.0.3, or 1.0.4. + + The optional parameters for deflateInit and inflateInit can now + be specified as an associative array in addition to a reference + to an associative array. They can also accept the -Name + syntax. + + gzopen can now optionally take a reference to an open + filehandle in place of a filename. In this case it will call + gzdopen. + + Added gzstream example script. + + 0.4 - Upgrade to support zlib 0.99 + + Added dictionary interface. + + Fixed bug in gzreadline - previously it would keep returning + the same buffer. This bug was reported by Helmut Jarausch + + Removed dependency to zutil.h and so dropped support for + + DEF_MEM_LEVEL (use MAX_MEM_LEVEL instead) + DEF_WBITS (use MAX_WBITS instead) + + 0.3 - Added prototype specification. + + 0.2 - Fixed a minor allocation problem in Zlib.xs + + 0.1 - first alpha release. 2nd October 1995 diff --git a/ext/IO-Compress/MANIFEST b/ext/IO-Compress/MANIFEST new file mode 100644 index 0000000000..a229755fd4 --- /dev/null +++ b/ext/IO-Compress/MANIFEST @@ -0,0 +1,151 @@ +Changes +examples/io/anycat +examples/io/bzip2/bzcat +examples/io/bzip2/bzgrep +examples/io/bzip2/bzstream +examples/io/gzip/gzappend +examples/io/gzip/gzcat +examples/io/gzip/gzgrep +examples/io/gzip/gzstream +examples/compress-zlib/filtinf +examples/compress-zlib/filtdef +examples/compress-zlib/gzcat +examples/compress-zlib/gzgrep +examples/compress-zlib/gzstream +lib/Compress/Zlib.pm +lib/File/GlobMapper.pm +lib/IO/Compress/Adapter/Bzip2.pm +lib/IO/Compress/Adapter/Deflate.pm +lib/IO/Compress/Adapter/Identity.pm +lib/IO/Compress/Base/Common.pm +lib/IO/Compress/Base.pm +lib/IO/Compress/Bzip2.pm +lib/IO/Compress/Deflate.pm +lib/IO/Compress/Gzip/Constants.pm +lib/IO/Compress/Gzip.pm +lib/IO/Compress/RawDeflate.pm +lib/IO/Compress/Zip/Constants.pm +lib/IO/Compress/Zip.pm +lib/IO/Compress/Zlib/Constants.pm +lib/IO/Compress/Zlib/Extra.pm +lib/IO/Uncompress/Adapter/Bunzip2.pm +lib/IO/Uncompress/Adapter/Identity.pm +lib/IO/Uncompress/Adapter/Inflate.pm +lib/IO/Uncompress/AnyInflate.pm +lib/IO/Uncompress/AnyUncompress.pm +lib/IO/Uncompress/Base.pm +lib/IO/Uncompress/Bunzip2.pm +lib/IO/Uncompress/Gunzip.pm +lib/IO/Uncompress/Inflate.pm +lib/IO/Uncompress/RawInflate.pm +lib/IO/Uncompress/Unzip.pm +Makefile.PL +MANIFEST +pod/FAQ.pod +private/MakeUtil.pm +README +t/000prereq.t +t/001bzip2.t +t/001zlib-generic-deflate.t +t/001zlib-generic-gzip.t +t/001zlib-generic-rawdeflate.t +t/001zlib-generic-zip.t +t/002any-deflate.t +t/002any-gzip.t +t/002any-rawdeflate.t +t/002any-transparent.t +t/002any-zip.t +t/004gziphdr.t +t/005defhdr.t +t/006zip.t +t/010examples-bzip2.t +t/010examples-zlib.t +t/01misc.t +t/020isize.t +t/050interop-gzip.t +t/100generic-bzip2.t +t/100generic-deflate.t +t/100generic-gzip.t +t/100generic-rawdeflate.t +t/100generic-zip.t +t/101truncate-bzip2.t +t/101truncate-deflate.t +t/101truncate-gzip.t +t/101truncate-rawdeflate.t +t/101truncate-zip.t +t/102tied-bzip2.t +t/102tied-deflate.t +t/102tied-gzip.t +t/102tied-rawdeflate.t +t/102tied-zip.t +t/103newtied-bzip2.t +t/103newtied-deflate.t +t/103newtied-gzip.t +t/103newtied-rawdeflate.t +t/103newtied-zip.t +t/104destroy-bzip2.t +t/104destroy-deflate.t +t/104destroy-gzip.t +t/104destroy-rawdeflate.t +t/104destroy-zip.t +t/105oneshot-bzip2.t +t/105oneshot-deflate.t +t/105oneshot-gzip-only.t +t/105oneshot-gzip.t +t/105oneshot-rawdeflate.t +t/105oneshot-zip-bzip2-only.t +t/105oneshot-zip-only.t +t/105oneshot-zip.t +t/106prime-bzip2.t +t/106prime-deflate.t +t/106prime-gzip.t +t/106prime-rawdeflate.t +t/106prime-zip.t +t/107multi-bzip2.t +t/107multi-deflate.t +t/107multi-gzip.t +t/107multi-rawdeflate.t +t/107multi-zip.t +t/108anyunc-bzip2.t +t/108anyunc-deflate.t +t/108anyunc-gzip.t +t/108anyunc-rawdeflate.t +t/108anyunc-transparent.t +t/108anyunc-zip.t +t/109merge-deflate.t +t/109merge-gzip.t +t/109merge-rawdeflate.t +t/109merge-zip.t +t/110encode-bzip2.t +t/110encode-deflate.t +t/110encode-gzip.t +t/110encode-rawdeflate.t +t/110encode-zip.t +t/999pod.t +t/99pod.t +t/cz-01version.t +t/cz-03zlib-v1.t* +t/cz-05examples.t +t/cz-06gzsetp.t +t/cz-08encoding.t +t/cz-14gzopen.t +t/cz-99pod.t +t/compress/any.pl +t/compress/anyunc.pl +t/compress/CompTestUtils.pm +t/compress/destroy.pl +t/compress/encode.pl +t/compress/generic.pl +t/compress/merge.pl +t/compress/multi.pl +t/compress/newtied.pl +t/compress/oneshot.pl +t/compress/prime.pl +t/compress/tied.pl +t/compress/truncate.pl +t/compress/zlib-generic.pl +t/globmapper.t +t/Test/Builder.pm +t/Test/More.pm +META.yml Module meta-data (added by MakeMaker) +t/Test/Simple.pm diff --git a/ext/IO-Compress/Makefile.PL b/ext/IO-Compress/Makefile.PL new file mode 100644 index 0000000000..b939d5924c --- /dev/null +++ b/ext/IO-Compress/Makefile.PL @@ -0,0 +1,47 @@ +#! perl -w + +use strict ; +require 5.004 ; + +$::VERSION = '2.017' ; + +use private::MakeUtil; +use ExtUtils::MakeMaker 5.16 ; + +UpDowngrade(getPerlFiles('MANIFEST')) + unless $ENV{PERL_CORE}; + +WriteMakefile( + NAME => 'IO::Compress', + VERSION_FROM => 'lib/IO/Compress/Base.pm', + 'dist' => { COMPRESS => 'gzip', + TARFLAGS => '-chvf', + SUFFIX => 'gz', + DIST_DEFAULT => 'MyTrebleCheck tardist', + }, + + ( + $ENV{SKIP_FOR_CORE} + ? (MAN3PODS => {}) + : (PREREQ_PM => { 'Compress::Raw::Bzip2' => $::VERSION, + 'Compress::Raw::Zlib' => $::VERSION, + $] >= 5.005 && $] < 5.006 + ? ('File::BSDGlob' => 0) + : () } + ) + ), + + ( + $] >= 5.005 + ? (ABSTRACT => 'IO Interface to compressed data files/buffers', + AUTHOR => 'Paul Marquess ') + : () + ), + + ((ExtUtils::MakeMaker->VERSION() gt '6.30') ? + ('LICENSE' => 'perl') : ()), + +) ; + +# end of file Makefile.PL + diff --git a/ext/IO-Compress/README b/ext/IO-Compress/README new file mode 100644 index 0000000000..07ae661601 --- /dev/null +++ b/ext/IO-Compress/README @@ -0,0 +1,94 @@ + + IO-Compress + + Version 2.017 + + 28th February 2009 + + Copyright (c) 1995-2009 Paul Marquess. All rights reserved. + This program is free software; you can redistribute it + and/or modify it under the same terms as Perl itself. + +DESCRIPTION +----------- + +This distribution provides a Perl interface to allow reading and writing of +compressed data created with the zlib and bziip2 libraries. + +The distribiution also ocontain the Compress::Zlib modeule. + +PREREQUISITES +------------- + +Before you can build IO-Compress you need to have the following +installed on your system: + + * Perl 5.004 or better. + * Compress::Raw::Zlib + * Compress::Raw::Bzip2 + +BUILDING THE MODULE +------------------- + +Assuming you have met all the prerequisites, the module can now be built +using this sequence of commands: + + perl Makefile.PL + make + make test + +INSTALLATION +------------ + +To install IO-Compress, run the command below: + + make install + +TROUBLESHOOTING +--------------- + +FEEDBACK +-------- + +How to report a problem with IO-Compress. + +To help me help you, I need all of the following information: + + 1. The Versions of everything relevant. + This includes: + + a. The *complete* output from running this + + perl -V + + Do not edit the output in any way. + Note, I want you to run "perl -V" and NOT "perl -v". + + If your perl does not understand the "-V" option it is too + old. This module needs Perl version 5.004 or better. + + b. The version of IO-Compress you have. + If you have successfully installed IO-Compress, this one-liner + will tell you: + + perl -MIO::Compress::Gzip -e 'print qq[ver $IO::Compress::Gzip::VERSION\n]' + + If you are running windows use this + + perl -MIO::Compress::Gzip -e "print qq[ver $IO::Compress::Gzip::VERSION\n]" + + If you haven't installed IO-Compress then search IO::Compress::Gzip.pm + for a line like this: + + $VERSION = "2.017" ; + + 2. If you are having problems building IO-Compress, send me a + complete log of what happened. Start by unpacking the IO-Compress + module into a fresh directory and keep a log of all the steps + + [edit config.in, if necessary] + perl Makefile.PL + make + make test TEST_VERBOSE=1 + +Paul Marquess diff --git a/ext/IO-Compress/examples/compress-zlib/filtdef b/ext/IO-Compress/examples/compress-zlib/filtdef new file mode 100755 index 0000000000..57dfeb9068 --- /dev/null +++ b/ext/IO-Compress/examples/compress-zlib/filtdef @@ -0,0 +1,29 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use Compress::Zlib ; + +binmode STDIN; +binmode STDOUT; +my $x = deflateInit() + or die "Cannot create a deflation stream\n" ; + +my ($output, $status) ; +while (<>) +{ + ($output, $status) = $x->deflate($_) ; + + $status == Z_OK + or die "deflation failed\n" ; + + print $output ; +} + +($output, $status) = $x->flush() ; + +$status == Z_OK + or die "deflation failed\n" ; + +print $output ; diff --git a/ext/IO-Compress/examples/compress-zlib/filtinf b/ext/IO-Compress/examples/compress-zlib/filtinf new file mode 100755 index 0000000000..1df202b1d7 --- /dev/null +++ b/ext/IO-Compress/examples/compress-zlib/filtinf @@ -0,0 +1,28 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use Compress::Zlib ; + +my $x = inflateInit() + or die "Cannot create a inflation stream\n" ; + +my $input = '' ; +binmode STDIN; +binmode STDOUT; + +my ($output, $status) ; +while (read(STDIN, $input, 4096)) +{ + ($output, $status) = $x->inflate(\$input) ; + + print $output + if $status == Z_OK or $status == Z_STREAM_END ; + + last if $status != Z_OK ; +} + +die "inflation failed\n" + unless $status == Z_STREAM_END ; + diff --git a/ext/IO-Compress/examples/compress-zlib/gzcat b/ext/IO-Compress/examples/compress-zlib/gzcat new file mode 100755 index 0000000000..5241a5a11f --- /dev/null +++ b/ext/IO-Compress/examples/compress-zlib/gzcat @@ -0,0 +1,27 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use Compress::Zlib ; + +#die "Usage: gzcat file...\n" +# unless @ARGV ; + +my $filename ; + +@ARGV = '-' unless @ARGV ; + +foreach my $filename (@ARGV) { + my $buffer ; + + my $gz = gzopen($filename, "rb") + or die "Cannot open $filename: $gzerrno\n" ; + + print $buffer while $gz->gzread($buffer) > 0 ; + + die "Error reading from $filename: $gzerrno" . ($gzerrno+0) . "\n" + if $gzerrno != Z_STREAM_END ; + + $gz->gzclose() ; +} diff --git a/ext/IO-Compress/examples/compress-zlib/gzgrep b/ext/IO-Compress/examples/compress-zlib/gzgrep new file mode 100755 index 0000000000..324d3e615f --- /dev/null +++ b/ext/IO-Compress/examples/compress-zlib/gzgrep @@ -0,0 +1,27 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use Compress::Zlib ; + +die "Usage: gzgrep pattern file...\n" + unless @ARGV >= 2; + +my $pattern = shift ; + +my $file ; + +foreach $file (@ARGV) { + my $gz = gzopen($file, "rb") + or die "Cannot open $file: $gzerrno\n" ; + + while ($gz->gzreadline($_) > 0) { + print if /$pattern/ ; + } + + die "Error reading from $file: $gzerrno\n" + if $gzerrno != Z_STREAM_END ; + + $gz->gzclose() ; +} diff --git a/ext/IO-Compress/examples/compress-zlib/gzstream b/ext/IO-Compress/examples/compress-zlib/gzstream new file mode 100755 index 0000000000..faacb0a0dd --- /dev/null +++ b/ext/IO-Compress/examples/compress-zlib/gzstream @@ -0,0 +1,19 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use Compress::Zlib ; + +binmode STDOUT; # gzopen only sets it on the fd + +#my $gz = gzopen(\*STDOUT, "wb") +my $gz = gzopen('-', "wb") + or die "Cannot open stdout: $gzerrno\n" ; + +while (<>) { + $gz->gzwrite($_) + or die "error writing: $gzerrno\n" ; +} + +$gz->gzclose ; diff --git a/ext/IO-Compress/examples/io/anycat b/ext/IO-Compress/examples/io/anycat new file mode 100755 index 0000000000..9db9c41faf --- /dev/null +++ b/ext/IO-Compress/examples/io/anycat @@ -0,0 +1,17 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; + +use IO::Uncompress::AnyInflate qw( anyinflate $AnyInflateError ); + +@ARGV = '-' unless @ARGV ; + +foreach my $file (@ARGV) { + + anyinflate $file => '-', + Transparent => 1, + Strict => 0, + or die "Cannot uncompress '$file': $AnyInflateError\n" ; + +} diff --git a/ext/IO-Compress/examples/io/bzip2/bzcat b/ext/IO-Compress/examples/io/bzip2/bzcat new file mode 100755 index 0000000000..7d7464377a --- /dev/null +++ b/ext/IO-Compress/examples/io/bzip2/bzcat @@ -0,0 +1,29 @@ +#!/usr/local/bin/perl + +use IO::Uncompress::Bunzip2 qw( $Bunzip2Error ); +use strict ; +local ($^W) = 1; #use warnings ; + +#die "Usage: gzcat file...\n" +# unless @ARGV ; + +my $file ; +my $buffer ; +my $s; + +@ARGV = '-' unless @ARGV ; + +foreach $file (@ARGV) { + + my $gz = new IO::Uncompress::Bunzip2 $file + or die "Cannot open $file: $Bunzip2Error\n" ; + + print $buffer + while ($s = $gz->read($buffer)) > 0 ; + + die "Error reading from $file: $Bunzip2Error\n" + if $s < 0 ; + + $gz->close() ; +} + diff --git a/ext/IO-Compress/examples/io/bzip2/bzgrep b/ext/IO-Compress/examples/io/bzip2/bzgrep new file mode 100755 index 0000000000..1ac162ca41 --- /dev/null +++ b/ext/IO-Compress/examples/io/bzip2/bzgrep @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use strict ; +local ($^W) = 1; #use warnings ; +use IO::Uncompress::Bunzip2 qw($Bunzip2Error); + +die "Usage: gzgrep pattern [file...]\n" + unless @ARGV >= 1; + +my $pattern = shift ; +my $file ; + +@ARGV = '-' unless @ARGV ; + +foreach $file (@ARGV) { + my $gz = new IO::Uncompress::Bunzip2 $file + or die "Cannot uncompress $file: $Bunzip2Error\n" ; + + while (<$gz>) { + print if /$pattern/ ; + } + + die "Error reading from $file: $Bunzip2Error\n" + if $Bunzip2Error ; +} diff --git a/ext/IO-Compress/examples/io/bzip2/bzstream b/ext/IO-Compress/examples/io/bzip2/bzstream new file mode 100755 index 0000000000..9bba3a5c4f --- /dev/null +++ b/ext/IO-Compress/examples/io/bzip2/bzstream @@ -0,0 +1,9 @@ +#!/usr/local/bin/perl + +use strict ; +local ($^W) = 1; #use warnings ; +use IO::Compress::Bzip2 qw(:all); + +bzip2 '-' => '-' + or die "bzstream: $Bzip2Error\n" ; + diff --git a/ext/IO-Compress/examples/io/gzip/gzappend b/ext/IO-Compress/examples/io/gzip/gzappend new file mode 100644 index 0000000000..a4a60a9aad --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzappend @@ -0,0 +1,24 @@ +#!/usr/local/bin/perl + +use IO::Compress::Gzip qw( $GzipError ); +use strict ; +use warnings ; + +die "Usage: gzappend gz-file file...\n" + unless @ARGV ; + + +my $output = shift @ARGV ; + +@ARGV = '-' unless @ARGV ; + +my $gz = new IO::Compress::Gzip $output, Merge => 1 + or die "Cannot open $output: $GzipError\n" ; + +$gz->write( [@ARGV] ) + or die "Cannot open $output: $GzipError\n" ; + +$gz->close; + + + diff --git a/ext/IO-Compress/examples/io/gzip/gzcat b/ext/IO-Compress/examples/io/gzip/gzcat new file mode 100755 index 0000000000..5572bae959 --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzcat @@ -0,0 +1,29 @@ +#!/usr/local/bin/perl + +use IO::Uncompress::Gunzip qw( $GunzipError ); +use strict ; +use warnings ; + +#die "Usage: gzcat file...\n" +# unless @ARGV ; + +my $file ; +my $buffer ; +my $s; + +@ARGV = '-' unless @ARGV ; + +foreach $file (@ARGV) { + + my $gz = new IO::Uncompress::Gunzip $file + or die "Cannot open $file: $GunzipError\n" ; + + print $buffer + while ($s = $gz->read($buffer)) > 0 ; + + die "Error reading from $file: $GunzipError\n" + if $s < 0 ; + + $gz->close() ; +} + diff --git a/ext/IO-Compress/examples/io/gzip/gzgrep b/ext/IO-Compress/examples/io/gzip/gzgrep new file mode 100755 index 0000000000..33820ba064 --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzgrep @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use strict ; +use warnings ; +use IO::Uncompress::Gunzip qw($GunzipError); + +die "Usage: gzgrep pattern [file...]\n" + unless @ARGV >= 1; + +my $pattern = shift ; +my $file ; + +@ARGV = '-' unless @ARGV ; + +foreach $file (@ARGV) { + my $gz = new IO::Uncompress::Gunzip $file + or die "Cannot uncompress $file: $GunzipError\n" ; + + while (<$gz>) { + print if /$pattern/ ; + } + + die "Error reading from $file: $GunzipError\n" + if $GunzipError ; +} + +__END__ +foreach $file (@ARGV) { + my $gz = gzopen($file, "rb") + or die "Cannot open $file: $gzerrno\n" ; + + while ($gz->gzreadline($_) > 0) { + print if /$pattern/ ; + } + + die "Error reading from $file: $gzerrno\n" + if $gzerrno != Z_STREAM_END ; + + $gz->gzclose() ; +} diff --git a/ext/IO-Compress/examples/io/gzip/gzstream b/ext/IO-Compress/examples/io/gzip/gzstream new file mode 100755 index 0000000000..9d03bc5749 --- /dev/null +++ b/ext/IO-Compress/examples/io/gzip/gzstream @@ -0,0 +1,24 @@ +#!/usr/local/bin/perl + +use strict ; +use warnings ; +use IO::Compress::Gzip qw(gzip $GzipError); + +gzip '-' => '-', Minimal => 1 + or die "gzstream: $GzipError\n" ; + +#exit 0; + +__END__ + +#my $gz = new IO::Compress::Gzip *STDOUT +my $gz = new IO::Compress::Gzip '-' + or die "gzstream: Cannot open stdout as gzip stream: $GzipError\n" ; + +while (<>) { + $gz->write($_) + or die "gzstream: Error writing gzip output stream: $GzipError\n" ; +} + +$gz->close + or die "gzstream: Error closing gzip output stream: $GzipError\n" ; diff --git a/ext/IO-Compress/lib/Compress/Zlib.pm b/ext/IO-Compress/lib/Compress/Zlib.pm new file mode 100644 index 0000000000..a95775282f --- /dev/null +++ b/ext/IO-Compress/lib/Compress/Zlib.pm @@ -0,0 +1,1456 @@ + +package Compress::Zlib; + +require 5.004 ; +require Exporter; +use AutoLoader; +use Carp ; +use IO::Handle ; +use Scalar::Util qw(dualvar); + +use IO::Compress::Base::Common 2.017 ; +use Compress::Raw::Zlib 2.017 ; +use IO::Compress::Gzip 2.017 ; +use IO::Uncompress::Gunzip 2.017 ; + +use strict ; +use warnings ; +use bytes ; +our ($VERSION, $XS_VERSION, @ISA, @EXPORT, $AUTOLOAD); + +$VERSION = '2.017'; +$XS_VERSION = $VERSION; +$VERSION = eval $VERSION; + +@ISA = qw(Exporter); +# Items to export into callers namespace by default. Note: do not export +# names by default without a very good reason. Use EXPORT_OK instead. +# Do not simply export all your public functions/methods/constants. +@EXPORT = qw( + deflateInit inflateInit + + compress uncompress + + gzopen $gzerrno + ); + +push @EXPORT, @Compress::Raw::Zlib::EXPORT ; + +BEGIN +{ + *zlib_version = \&Compress::Raw::Zlib::zlib_version; +} + +sub AUTOLOAD { + my($constname); + ($constname = $AUTOLOAD) =~ s/.*:://; + my ($error, $val) = Compress::Raw::Zlib::constant($constname); + Carp::croak $error if $error; + no strict 'refs'; + *{$AUTOLOAD} = sub { $val }; + goto &{$AUTOLOAD}; +} + +use constant FLAG_APPEND => 1 ; +use constant FLAG_CRC => 2 ; +use constant FLAG_ADLER => 4 ; +use constant FLAG_CONSUME_INPUT => 8 ; + +our (@my_z_errmsg); + +@my_z_errmsg = ( + "need dictionary", # Z_NEED_DICT 2 + "stream end", # Z_STREAM_END 1 + "", # Z_OK 0 + "file error", # Z_ERRNO (-1) + "stream error", # Z_STREAM_ERROR (-2) + "data error", # Z_DATA_ERROR (-3) + "insufficient memory", # Z_MEM_ERROR (-4) + "buffer error", # Z_BUF_ERROR (-5) + "incompatible version",# Z_VERSION_ERROR(-6) + ); + + +sub _set_gzerr +{ + my $value = shift ; + + if ($value == 0) { + $Compress::Zlib::gzerrno = 0 ; + } + elsif ($value == Z_ERRNO() || $value > 2) { + $Compress::Zlib::gzerrno = $! ; + } + else { + $Compress::Zlib::gzerrno = dualvar($value+0, $my_z_errmsg[2 - $value]); + } + + return $value ; +} + +sub _save_gzerr +{ + my $gz = shift ; + my $test_eof = shift ; + + my $value = $gz->errorNo() || 0 ; + + if ($test_eof) { + #my $gz = $self->[0] ; + # gzread uses Z_STREAM_END to denote a successful end + $value = Z_STREAM_END() if $gz->eof() && $value == 0 ; + } + + _set_gzerr($value) ; +} + +sub gzopen($$) +{ + my ($file, $mode) = @_ ; + + my $gz ; + my %defOpts = (Level => Z_DEFAULT_COMPRESSION(), + Strategy => Z_DEFAULT_STRATEGY(), + ); + + my $writing ; + $writing = ! ($mode =~ /r/i) ; + $writing = ($mode =~ /[wa]/i) ; + + $defOpts{Level} = $1 if $mode =~ /(\d)/; + $defOpts{Strategy} = Z_FILTERED() if $mode =~ /f/i; + $defOpts{Strategy} = Z_HUFFMAN_ONLY() if $mode =~ /h/i; + $defOpts{Append} = 1 if $mode =~ /a/i; + + my $infDef = $writing ? 'deflate' : 'inflate'; + my @params = () ; + + croak "gzopen: file parameter is not a filehandle or filename" + unless isaFilehandle $file || isaFilename $file || + (ref $file && ref $file eq 'SCALAR'); + + return undef unless $mode =~ /[rwa]/i ; + + _set_gzerr(0) ; + + if ($writing) { + $gz = new IO::Compress::Gzip($file, Minimal => 1, AutoClose => 1, + %defOpts) + or $Compress::Zlib::gzerrno = $IO::Compress::Gzip::GzipError; + } + else { + $gz = new IO::Uncompress::Gunzip($file, + Transparent => 1, + Append => 0, + AutoClose => 1, + MultiStream => 1, + Strict => 0) + or $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError; + } + + return undef + if ! defined $gz ; + + bless [$gz, $infDef], 'Compress::Zlib::gzFile'; +} + +sub Compress::Zlib::gzFile::gzread +{ + my $self = shift ; + + return _set_gzerr(Z_STREAM_ERROR()) + if $self->[1] ne 'inflate'; + + my $len = defined $_[1] ? $_[1] : 4096 ; + + if ($self->gzeof() || $len == 0) { + # Zap the output buffer to match ver 1 behaviour. + $_[0] = "" ; + return 0 ; + } + + my $gz = $self->[0] ; + my $status = $gz->read($_[0], $len) ; + _save_gzerr($gz, 1); + return $status ; +} + +sub Compress::Zlib::gzFile::gzreadline +{ + my $self = shift ; + + my $gz = $self->[0] ; + { + # Maintain backward compatibility with 1.x behaviour + # It didn't support $/, so this can't either. + local $/ = "\n" ; + $_[0] = $gz->getline() ; + } + _save_gzerr($gz, 1); + return defined $_[0] ? length $_[0] : 0 ; +} + +sub Compress::Zlib::gzFile::gzwrite +{ + my $self = shift ; + my $gz = $self->[0] ; + + return _set_gzerr(Z_STREAM_ERROR()) + if $self->[1] ne 'deflate'; + + $] >= 5.008 and (utf8::downgrade($_[0], 1) + or croak "Wide character in gzwrite"); + + my $status = $gz->write($_[0]) ; + _save_gzerr($gz); + return $status ; +} + +sub Compress::Zlib::gzFile::gztell +{ + my $self = shift ; + my $gz = $self->[0] ; + my $status = $gz->tell() ; + _save_gzerr($gz); + return $status ; +} + +sub Compress::Zlib::gzFile::gzseek +{ + my $self = shift ; + my $offset = shift ; + my $whence = shift ; + + my $gz = $self->[0] ; + my $status ; + eval { $status = $gz->seek($offset, $whence) ; }; + if ($@) + { + my $error = $@; + $error =~ s/^.*: /gzseek: /; + $error =~ s/ at .* line \d+\s*$//; + croak $error; + } + _save_gzerr($gz); + return $status ; +} + +sub Compress::Zlib::gzFile::gzflush +{ + my $self = shift ; + my $f = shift ; + + my $gz = $self->[0] ; + my $status = $gz->flush($f) ; + my $err = _save_gzerr($gz); + return $status ? 0 : $err; +} + +sub Compress::Zlib::gzFile::gzclose +{ + my $self = shift ; + my $gz = $self->[0] ; + + my $status = $gz->close() ; + my $err = _save_gzerr($gz); + return $status ? 0 : $err; +} + +sub Compress::Zlib::gzFile::gzeof +{ + my $self = shift ; + my $gz = $self->[0] ; + + return 0 + if $self->[1] ne 'inflate'; + + my $status = $gz->eof() ; + _save_gzerr($gz); + return $status ; +} + +sub Compress::Zlib::gzFile::gzsetparams +{ + my $self = shift ; + croak "Usage: Compress::Zlib::gzFile::gzsetparams(file, level, strategy)" + unless @_ eq 2 ; + + my $gz = $self->[0] ; + my $level = shift ; + my $strategy = shift; + + return _set_gzerr(Z_STREAM_ERROR()) + if $self->[1] ne 'deflate'; + + my $status = *$gz->{Compress}->deflateParams(-Level => $level, + -Strategy => $strategy); + _save_gzerr($gz); + return $status ; +} + +sub Compress::Zlib::gzFile::gzerror +{ + my $self = shift ; + my $gz = $self->[0] ; + + return $Compress::Zlib::gzerrno ; +} + + +sub compress($;$) +{ + my ($x, $output, $err, $in) =('', '', '', '') ; + + if (ref $_[0] ) { + $in = $_[0] ; + croak "not a scalar reference" unless ref $in eq 'SCALAR' ; + } + else { + $in = \$_[0] ; + } + + $] >= 5.008 and (utf8::downgrade($$in, 1) + or croak "Wide character in compress"); + + my $level = (@_ == 2 ? $_[1] : Z_DEFAULT_COMPRESSION() ); + + $x = new Compress::Raw::Zlib::Deflate -AppendOutput => 1, -Level => $level + or return undef ; + + $err = $x->deflate($in, $output) ; + return undef unless $err == Z_OK() ; + + $err = $x->flush($output) ; + return undef unless $err == Z_OK() ; + + return $output ; + +} + +sub uncompress($) +{ + my ($x, $output, $err, $in) =('', '', '', '') ; + + if (ref $_[0] ) { + $in = $_[0] ; + croak "not a scalar reference" unless ref $in eq 'SCALAR' ; + } + else { + $in = \$_[0] ; + } + + $] >= 5.008 and (utf8::downgrade($$in, 1) + or croak "Wide character in uncompress"); + + $x = new Compress::Raw::Zlib::Inflate -ConsumeInput => 0 or return undef ; + + $err = $x->inflate($in, $output) ; + return undef unless $err == Z_STREAM_END() ; + + return $output ; +} + + + +sub deflateInit(@) +{ + my ($got) = ParseParameters(0, + { + 'Bufsize' => [1, 1, Parse_unsigned, 4096], + 'Level' => [1, 1, Parse_signed, Z_DEFAULT_COMPRESSION()], + 'Method' => [1, 1, Parse_unsigned, Z_DEFLATED()], + 'WindowBits' => [1, 1, Parse_signed, MAX_WBITS()], + 'MemLevel' => [1, 1, Parse_unsigned, MAX_MEM_LEVEL()], + 'Strategy' => [1, 1, Parse_unsigned, Z_DEFAULT_STRATEGY()], + 'Dictionary' => [1, 1, Parse_any, ""], + }, @_ ) ; + + croak "Compress::Zlib::deflateInit: Bufsize must be >= 1, you specified " . + $got->value('Bufsize') + unless $got->value('Bufsize') >= 1; + + my $obj ; + + my $status = 0 ; + ($obj, $status) = + Compress::Raw::Zlib::_deflateInit(0, + $got->value('Level'), + $got->value('Method'), + $got->value('WindowBits'), + $got->value('MemLevel'), + $got->value('Strategy'), + $got->value('Bufsize'), + $got->value('Dictionary')) ; + + my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldDeflate" : undef) ; + return wantarray ? ($x, $status) : $x ; +} + +sub inflateInit(@) +{ + my ($got) = ParseParameters(0, + { + 'Bufsize' => [1, 1, Parse_unsigned, 4096], + 'WindowBits' => [1, 1, Parse_signed, MAX_WBITS()], + 'Dictionary' => [1, 1, Parse_any, ""], + }, @_) ; + + + croak "Compress::Zlib::inflateInit: Bufsize must be >= 1, you specified " . + $got->value('Bufsize') + unless $got->value('Bufsize') >= 1; + + my $status = 0 ; + my $obj ; + ($obj, $status) = Compress::Raw::Zlib::_inflateInit(FLAG_CONSUME_INPUT, + $got->value('WindowBits'), + $got->value('Bufsize'), + $got->value('Dictionary')) ; + + my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldInflate" : undef) ; + + wantarray ? ($x, $status) : $x ; +} + +package Zlib::OldDeflate ; + +our (@ISA); +@ISA = qw(Compress::Raw::Zlib::deflateStream); + + +sub deflate +{ + my $self = shift ; + my $output ; + + my $status = $self->SUPER::deflate($_[0], $output) ; + wantarray ? ($output, $status) : $output ; +} + +sub flush +{ + my $self = shift ; + my $output ; + my $flag = shift || Compress::Zlib::Z_FINISH(); + my $status = $self->SUPER::flush($output, $flag) ; + + wantarray ? ($output, $status) : $output ; +} + +package Zlib::OldInflate ; + +our (@ISA); +@ISA = qw(Compress::Raw::Zlib::inflateStream); + +sub inflate +{ + my $self = shift ; + my $output ; + my $status = $self->SUPER::inflate($_[0], $output) ; + wantarray ? ($output, $status) : $output ; +} + +package Compress::Zlib ; + +use IO::Compress::Gzip::Constants 2.017 ; + +sub memGzip($) +{ + my $out; + + # if the deflation buffer isn't a reference, make it one + my $string = (ref $_[0] ? $_[0] : \$_[0]) ; + + $] >= 5.008 and (utf8::downgrade($$string, 1) + or croak "Wide character in memGzip"); + + IO::Compress::Gzip::gzip($string, \$out, Minimal => 1) + or return undef ; + + return $out; +} + + +sub _removeGzipHeader($) +{ + my $string = shift ; + + return Z_DATA_ERROR() + if length($$string) < GZIP_MIN_HEADER_SIZE ; + + my ($magic1, $magic2, $method, $flags, $time, $xflags, $oscode) = + unpack ('CCCCVCC', $$string); + + return Z_DATA_ERROR() + unless $magic1 == GZIP_ID1 and $magic2 == GZIP_ID2 and + $method == Z_DEFLATED() and !($flags & GZIP_FLG_RESERVED) ; + substr($$string, 0, GZIP_MIN_HEADER_SIZE) = '' ; + + # skip extra field + if ($flags & GZIP_FLG_FEXTRA) + { + return Z_DATA_ERROR() + if length($$string) < GZIP_FEXTRA_HEADER_SIZE ; + + my ($extra_len) = unpack ('v', $$string); + $extra_len += GZIP_FEXTRA_HEADER_SIZE; + return Z_DATA_ERROR() + if length($$string) < $extra_len ; + + substr($$string, 0, $extra_len) = ''; + } + + # skip orig name + if ($flags & GZIP_FLG_FNAME) + { + my $name_end = index ($$string, GZIP_NULL_BYTE); + return Z_DATA_ERROR() + if $name_end == -1 ; + substr($$string, 0, $name_end + 1) = ''; + } + + # skip comment + if ($flags & GZIP_FLG_FCOMMENT) + { + my $comment_end = index ($$string, GZIP_NULL_BYTE); + return Z_DATA_ERROR() + if $comment_end == -1 ; + substr($$string, 0, $comment_end + 1) = ''; + } + + # skip header crc + if ($flags & GZIP_FLG_FHCRC) + { + return Z_DATA_ERROR() + if length ($$string) < GZIP_FHCRC_SIZE ; + substr($$string, 0, GZIP_FHCRC_SIZE) = ''; + } + + return Z_OK(); +} + + +sub memGunzip($) +{ + # if the buffer isn't a reference, make it one + my $string = (ref $_[0] ? $_[0] : \$_[0]); + + $] >= 5.008 and (utf8::downgrade($$string, 1) + or croak "Wide character in memGunzip"); + + _removeGzipHeader($string) == Z_OK() + or return undef; + + my $bufsize = length $$string > 4096 ? length $$string : 4096 ; + my $x = new Compress::Raw::Zlib::Inflate({-WindowBits => - MAX_WBITS(), + -Bufsize => $bufsize}) + + or return undef; + + my $output = "" ; + my $status = $x->inflate($string, $output); + return undef + unless $status == Z_STREAM_END(); + + if (length $$string >= 8) + { + my ($crc, $len) = unpack ("VV", substr($$string, 0, 8)); + substr($$string, 0, 8) = ''; + return undef + unless $len == length($output) and + $crc == crc32($output); + } + else + { + $$string = ''; + } + return $output; +} + +# Autoload methods go after __END__, and are processed by the autosplit program. + +1; +__END__ + + +=head1 NAME + +Compress::Zlib - Interface to zlib compression library + +=head1 SYNOPSIS + + use Compress::Zlib ; + + ($d, $status) = deflateInit( [OPT] ) ; + $status = $d->deflate($input, $output) ; + $status = $d->flush([$flush_type]) ; + $d->deflateParams(OPTS) ; + $d->deflateTune(OPTS) ; + $d->dict_adler() ; + $d->crc32() ; + $d->adler32() ; + $d->total_in() ; + $d->total_out() ; + $d->msg() ; + $d->get_Strategy(); + $d->get_Level(); + $d->get_BufSize(); + + ($i, $status) = inflateInit( [OPT] ) ; + $status = $i->inflate($input, $output [, $eof]) ; + $status = $i->inflateSync($input) ; + $i->dict_adler() ; + $d->crc32() ; + $d->adler32() ; + $i->total_in() ; + $i->total_out() ; + $i->msg() ; + $d->get_BufSize(); + + $dest = compress($source) ; + $dest = uncompress($source) ; + + $gz = gzopen($filename or filehandle, $mode) ; + $bytesread = $gz->gzread($buffer [,$size]) ; + $bytesread = $gz->gzreadline($line) ; + $byteswritten = $gz->gzwrite($buffer) ; + $status = $gz->gzflush($flush) ; + $offset = $gz->gztell() ; + $status = $gz->gzseek($offset, $whence) ; + $status = $gz->gzclose() ; + $status = $gz->gzeof() ; + $status = $gz->gzsetparams($level, $strategy) ; + $errstring = $gz->gzerror() ; + $gzerrno + + $dest = Compress::Zlib::memGzip($buffer) ; + $dest = Compress::Zlib::memGunzip($buffer) ; + + $crc = adler32($buffer [,$crc]) ; + $crc = crc32($buffer [,$crc]) ; + + $crc = adler32_combine($crc1, $crc2, $len2)l + $crc = crc32_combine($adler1, $adler2, $len2) + + my $version = Compress::Raw::Zlib::zlib_version(); + +=head1 DESCRIPTION + +The I module provides a Perl interface to the I +compression library (see L for details about where to get +I). + +The C module can be split into two general areas of +functionality, namely a simple read/write interface to I files +and a low-level in-memory compression/decompression interface. + +Each of these areas will be discussed in the following sections. + +=head2 Notes for users of Compress::Zlib version 1 + +The main change in C version 2.x is that it does not now +interface directly to the zlib library. Instead it uses the +C and C modules for +reading/writing gzip files, and the C module for some +low-level zlib access. + +The interface provided by version 2 of this module should be 100% backward +compatible with version 1. If you find a difference in the expected +behaviour please contact the author (See L). See L + +With the creation of the C and C modules no +new features are planned for C - the new modules do +everything that C does and then some. Development on +C will be limited to bug fixes only. + +If you are writing new code, your first port of call should be one of the +new C or C modules. + +=head1 GZIP INTERFACE + +A number of functions are supplied in I for reading and writing +I files that conform to RFC 1952. This module provides an interface +to most of them. + +If you have previously used C 1.x, the following +enhancements/changes have been made to the C interface: + +=over 5 + +=item 1 + +If you want to to open either STDIN or STDOUT with C, you can now +optionally use the special filename "C<->" as a synonym for C<\*STDIN> and +C<\*STDOUT>. + +=item 2 + +In C version 1.x, C used the zlib library to open +the underlying file. This made things especially tricky when a Perl +filehandle was passed to C. Behind the scenes the numeric C file +descriptor had to be extracted from the Perl filehandle and this passed to +the zlib library. + +Apart from being non-portable to some operating systems, this made it +difficult to use C in situations where you wanted to extract/create +a gzip data stream that is embedded in a larger file, without having to +resort to opening and closing the file multiple times. + +It also made it impossible to pass a perl filehandle that wasn't associated +with a real filesystem file, like, say, an C. + +In C version 2.x, the C interface has been +completely rewritten to use the L +for writing gzip files and L +for reading gzip files. None of the limitations mentioned above apply. + +=item 3 + +Addition of C to provide a restricted C interface. + +=item 4. + +Added C. + +=back + +A more complete and flexible interface for reading/writing gzip +files/buffers is included with the module C. See +L and +L for more details. + +=over 5 + +=item B<$gz = gzopen($filename, $mode)> + +=item B<$gz = gzopen($filehandle, $mode)> + +This function opens either the I file C<$filename> for reading or +writing or attaches to the opened filehandle, C<$filehandle>. +It returns an object on success and C on failure. + +When writing a gzip file this interface will I create the smallest +possible gzip header (exactly 10 bytes). If you want greater control over +what gets stored in the gzip header (like the original filename or a +comment) use L instead. Similarly if +you want to read the contents of the gzip header use +L. + +The second parameter, C<$mode>, is used to specify whether the file is +opened for reading or writing and to optionally specify a compression +level and compression strategy when writing. The format of the C<$mode> +parameter is similar to the mode parameter to the 'C' function C, +so "rb" is used to open for reading, "wb" for writing and "ab" for +appending (writing at the end of the file). + +To specify a compression level when writing, append a digit between 0 +and 9 to the mode string -- 0 means no compression and 9 means maximum +compression. +If no compression level is specified Z_DEFAULT_COMPRESSION is used. + +To specify the compression strategy when writing, append 'f' for filtered +data, 'h' for Huffman only compression, or 'R' for run-length encoding. +If no strategy is specified Z_DEFAULT_STRATEGY is used. + +So, for example, "wb9" means open for writing with the maximum compression +using the default strategy and "wb4R" means open for writing with compression +level 4 and run-length encoding. + +Refer to the I documentation for the exact format of the C<$mode> +parameter. + +=item B<$bytesread = $gz-Egzread($buffer [, $size]) ;> + +Reads C<$size> bytes from the compressed file into C<$buffer>. If +C<$size> is not specified, it will default to 4096. If the scalar +C<$buffer> is not large enough, it will be extended automatically. + +Returns the number of bytes actually read. On EOF it returns 0 and in +the case of an error, -1. + +=item B<$bytesread = $gz-Egzreadline($line) ;> + +Reads the next line from the compressed file into C<$line>. + +Returns the number of bytes actually read. On EOF it returns 0 and in +the case of an error, -1. + +It is legal to intermix calls to C and C. + +To maintain backward compatibility with version 1.x of this module +C ignores the C<$/> variable - it I uses the string +C<"\n"> as the line delimiter. + +If you want to read a gzip file a line at a time and have it respect the +C<$/> variable (or C<$INPUT_RECORD_SEPARATOR>, or C<$RS> when C is +in use) see L. + +=item B<$byteswritten = $gz-Egzwrite($buffer) ;> + +Writes the contents of C<$buffer> to the compressed file. Returns the +number of bytes actually written, or 0 on error. + +=item B<$status = $gz-Egzflush($flush_type) ;> + +Flushes all pending output into the compressed file. + +This method takes an optional parameter, C<$flush_type>, that controls +how the flushing will be carried out. By default the C<$flush_type> +used is C. Other valid values for C<$flush_type> are +C, C, C and C. It is +strongly recommended that you only set the C parameter if +you fully understand the implications of what it does - overuse of C +can seriously degrade the level of compression achieved. See the C +documentation for details. + +Returns 0 on success. + +=item B<$offset = $gz-Egztell() ;> + +Returns the uncompressed file offset. + +=item B<$status = $gz-Egzseek($offset, $whence) ;> + +Provides a sub-set of the C functionality, with the restriction +that it is only legal to seek forward in the compressed file. +It is a fatal error to attempt to seek backward. + +When opened for writing, empty parts of the file will have NULL (0x00) +bytes written to them. + +The C<$whence> parameter should be one of SEEK_SET, SEEK_CUR or SEEK_END. + +Returns 1 on success, 0 on failure. + +=item B<$gz-Egzclose> + +Closes the compressed file. Any pending data is flushed to the file +before it is closed. + +Returns 0 on success. + +=item B<$gz-Egzsetparams($level, $strategy> + +Change settings for the deflate stream C<$gz>. + +The list of the valid options is shown below. Options not specified +will remain unchanged. + +Note: This method is only available if you are running zlib 1.0.6 or better. + +=over 5 + +=item B<$level> + +Defines the compression level. Valid values are 0 through 9, +C, C, C, and +C. + +=item B<$strategy> + +Defines the strategy used to tune the compression. The valid values are +C, C and C. + +=back + +=item B<$gz-Egzerror> + +Returns the I error message or number for the last operation +associated with C<$gz>. The return value will be the I error +number when used in a numeric context and the I error message +when used in a string context. The I error number constants, +shown below, are available for use. + + Z_OK + Z_STREAM_END + Z_ERRNO + Z_STREAM_ERROR + Z_DATA_ERROR + Z_MEM_ERROR + Z_BUF_ERROR + +=item B<$gzerrno> + +The C<$gzerrno> scalar holds the error code associated with the most +recent I routine. Note that unlike C, the error is +I associated with a particular file. + +As with C it returns an error number in numeric context and +an error message in string context. Unlike C though, the +error message will correspond to the I message when the error is +associated with I itself, or the UNIX error message when it is +not (i.e. I returned C). + +As there is an overlap between the error numbers used by I and +UNIX, C<$gzerrno> should only be used to check for the presence of +I error in numeric context. Use C to check for specific +I errors. The I example below shows how the variable can +be used safely. + +=back + +=head2 Examples + +Here is an example script which uses the interface. It implements a +I function. + + use strict ; + use warnings ; + + use Compress::Zlib ; + + # use stdin if no files supplied + @ARGV = '-' unless @ARGV ; + + foreach my $file (@ARGV) { + my $buffer ; + + my $gz = gzopen($file, "rb") + or die "Cannot open $file: $gzerrno\n" ; + + print $buffer while $gz->gzread($buffer) > 0 ; + + die "Error reading from $file: $gzerrno" . ($gzerrno+0) . "\n" + if $gzerrno != Z_STREAM_END ; + + $gz->gzclose() ; + } + +Below is a script which makes use of C. It implements a +very simple I like script. + + use strict ; + use warnings ; + + use Compress::Zlib ; + + die "Usage: gzgrep pattern [file...]\n" + unless @ARGV >= 1; + + my $pattern = shift ; + + # use stdin if no files supplied + @ARGV = '-' unless @ARGV ; + + foreach my $file (@ARGV) { + my $gz = gzopen($file, "rb") + or die "Cannot open $file: $gzerrno\n" ; + + while ($gz->gzreadline($_) > 0) { + print if /$pattern/ ; + } + + die "Error reading from $file: $gzerrno\n" + if $gzerrno != Z_STREAM_END ; + + $gz->gzclose() ; + } + +This script, I, does the opposite of the I script +above. It reads from standard input and writes a gzip data stream to +standard output. + + use strict ; + use warnings ; + + use Compress::Zlib ; + + binmode STDOUT; # gzopen only sets it on the fd + + my $gz = gzopen(\*STDOUT, "wb") + or die "Cannot open stdout: $gzerrno\n" ; + + while (<>) { + $gz->gzwrite($_) + or die "error writing: $gzerrno\n" ; + } + + $gz->gzclose ; + +=head2 Compress::Zlib::memGzip + +This function is used to create an in-memory gzip file with the minimum +possible gzip header (exactly 10 bytes). + + $dest = Compress::Zlib::memGzip($buffer) ; + +If successful, it returns the in-memory gzip file, otherwise it returns +undef. + +The C<$buffer> parameter can either be a scalar or a scalar reference. + +See L for an alternative way to +carry out in-memory gzip compression. + +=head2 Compress::Zlib::memGunzip + +This function is used to uncompress an in-memory gzip file. + + $dest = Compress::Zlib::memGunzip($buffer) ; + +If successful, it returns the uncompressed gzip file, otherwise it +returns undef. + +The C<$buffer> parameter can either be a scalar or a scalar reference. The +contents of the C<$buffer> parameter are destroyed after calling this function. + +See L for an alternative way +to carry out in-memory gzip uncompression. + +=head1 COMPRESS/UNCOMPRESS + +Two functions are provided to perform in-memory compression/uncompression of +RFC 1950 data streams. They are called C and C. + +=over 5 + +=item B<$dest = compress($source [, $level] ) ;> + +Compresses C<$source>. If successful it returns the compressed +data. Otherwise it returns I. + +The source buffer, C<$source>, can either be a scalar or a scalar +reference. + +The C<$level> parameter defines the compression level. Valid values are +0 through 9, C, C, +C, and C. +If C<$level> is not specified C will be used. + +=item B<$dest = uncompress($source) ;> + +Uncompresses C<$source>. If successful it returns the uncompressed +data. Otherwise it returns I. + +The source buffer can either be a scalar or a scalar reference. + +=back + +Please note: the two functions defined above are I compatible with +the Unix commands of the same name. + +See L and L included with +this distribution for an alternative interface for reading/writing RFC 1950 +files/buffers. + +=head1 Deflate Interface + +This section defines an interface that allows in-memory compression using +the I interface provided by zlib. + +Here is a definition of the interface available: + +=head2 B<($d, $status) = deflateInit( [OPT] )> + +Initialises a deflation stream. + +It combines the features of the I functions C, +C and C. + +If successful, it will return the initialised deflation stream, C<$d> +and C<$status> of C in a list context. In scalar context it +returns the deflation stream, C<$d>, only. + +If not successful, the returned deflation stream (C<$d>) will be +I and C<$status> will hold the exact I error code. + +The function optionally takes a number of named options specified as +C<< -Name=>value >> pairs. This allows individual options to be +tailored without having to specify them all in the parameter list. + +For backward compatibility, it is also possible to pass the parameters +as a reference to a hash containing the name=>value pairs. + +The function takes one optional parameter, a reference to a hash. The +contents of the hash allow the deflation interface to be tailored. + +Here is a list of the valid options: + +=over 5 + +=item B<-Level> + +Defines the compression level. Valid values are 0 through 9, +C, C, C, and +C. + +The default is Z_DEFAULT_COMPRESSION. + +=item B<-Method> + +Defines the compression method. The only valid value at present (and +the default) is Z_DEFLATED. + +=item B<-WindowBits> + +To create an RFC 1950 data stream, set C to a positive number. + +To create an RFC 1951 data stream, set C to C<-MAX_WBITS>. + +For a full definition of the meaning and valid values for C refer +to the I documentation for I. + +Defaults to MAX_WBITS. + +=item B<-MemLevel> + +For a definition of the meaning and valid values for C +refer to the I documentation for I. + +Defaults to MAX_MEM_LEVEL. + +=item B<-Strategy> + +Defines the strategy used to tune the compression. The valid values are +C, C and C. + +The default is Z_DEFAULT_STRATEGY. + +=item B<-Dictionary> + +When a dictionary is specified I will automatically +call C directly after calling C. The +Adler32 value for the dictionary can be obtained by calling the method +C<$d->dict_adler()>. + +The default is no dictionary. + +=item B<-Bufsize> + +Sets the initial size for the deflation buffer. If the buffer has to be +reallocated to increase the size, it will grow in increments of +C. + +The default is 4096. + +=back + +Here is an example of using the C optional parameter list +to override the default buffer size and compression level. All other +options will take their default values. + + deflateInit( -Bufsize => 300, + -Level => Z_BEST_SPEED ) ; + +=head2 B<($out, $status) = $d-Edeflate($buffer)> + +Deflates the contents of C<$buffer>. The buffer can either be a scalar +or a scalar reference. When finished, C<$buffer> will be +completely processed (assuming there were no errors). If the deflation +was successful it returns the deflated output, C<$out>, and a status +value, C<$status>, of C. + +On error, C<$out> will be I and C<$status> will contain the +I error code. + +In a scalar context C will return C<$out> only. + +As with the I function in I, it is not necessarily the +case that any output will be produced by this method. So don't rely on +the fact that C<$out> is empty for an error test. + +=head2 B<($out, $status) = $d-Eflush()> +=head2 B<($out, $status) = $d-Eflush($flush_type)> + +Typically used to finish the deflation. Any pending output will be +returned via C<$out>. +C<$status> will have a value C if successful. + +In a scalar context C will return C<$out> only. + +Note that flushing can seriously degrade the compression ratio, so it +should only be used to terminate a decompression (using C) or +when you want to create a I (using C). + +By default the C used is C. Other valid values +for C are C, C, C +and C. It is strongly recommended that you only set the +C parameter if you fully understand the implications of +what it does. See the C documentation for details. + +=head2 B<$status = $d-EdeflateParams([OPT])> + +Change settings for the deflate stream C<$d>. + +The list of the valid options is shown below. Options not specified +will remain unchanged. + +=over 5 + +=item B<-Level> + +Defines the compression level. Valid values are 0 through 9, +C, C, C, and +C. + +=item B<-Strategy> + +Defines the strategy used to tune the compression. The valid values are +C, C and C. + +=back + +=head2 B<$d-Edict_adler()> + +Returns the adler32 value for the dictionary. + +=head2 B<$d-Emsg()> + +Returns the last error message generated by zlib. + +=head2 B<$d-Etotal_in()> + +Returns the total number of bytes uncompressed bytes input to deflate. + +=head2 B<$d-Etotal_out()> + +Returns the total number of compressed bytes output from deflate. + +=head2 Example + +Here is a trivial example of using C. It simply reads standard +input, deflates it and writes it to standard output. + + use strict ; + use warnings ; + + use Compress::Zlib ; + + binmode STDIN; + binmode STDOUT; + my $x = deflateInit() + or die "Cannot create a deflation stream\n" ; + + my ($output, $status) ; + while (<>) + { + ($output, $status) = $x->deflate($_) ; + + $status == Z_OK + or die "deflation failed\n" ; + + print $output ; + } + + ($output, $status) = $x->flush() ; + + $status == Z_OK + or die "deflation failed\n" ; + + print $output ; + +=head1 Inflate Interface + +This section defines the interface available that allows in-memory +uncompression using the I interface provided by zlib. + +Here is a definition of the interface: + +=head2 B<($i, $status) = inflateInit()> + +Initialises an inflation stream. + +In a list context it returns the inflation stream, C<$i>, and the +I status code in C<$status>. In a scalar context it returns the +inflation stream only. + +If successful, C<$i> will hold the inflation stream and C<$status> will +be C. + +If not successful, C<$i> will be I and C<$status> will hold the +I error code. + +The function optionally takes a number of named options specified as +C<< -Name=>value >> pairs. This allows individual options to be +tailored without having to specify them all in the parameter list. + +For backward compatibility, it is also possible to pass the parameters +as a reference to a hash containing the name=>value pairs. + +The function takes one optional parameter, a reference to a hash. The +contents of the hash allow the deflation interface to be tailored. + +Here is a list of the valid options: + +=over 5 + +=item B<-WindowBits> + +To uncompress an RFC 1950 data stream, set C to a positive number. + +To uncompress an RFC 1951 data stream, set C to C<-MAX_WBITS>. + +For a full definition of the meaning and valid values for C refer +to the I documentation for I. + +Defaults to MAX_WBITS. + +=item B<-Bufsize> + +Sets the initial size for the inflation buffer. If the buffer has to be +reallocated to increase the size, it will grow in increments of +C. + +Default is 4096. + +=item B<-Dictionary> + +The default is no dictionary. + +=back + +Here is an example of using the C optional parameter to +override the default buffer size. + + inflateInit( -Bufsize => 300 ) ; + +=head2 B<($out, $status) = $i-Einflate($buffer)> + +Inflates the complete contents of C<$buffer>. The buffer can either be +a scalar or a scalar reference. + +Returns C if successful and C if the end of the +compressed data has been successfully reached. +If not successful, C<$out> will be I and C<$status> will hold +the I error code. + +The C<$buffer> parameter is modified by C. On completion it +will contain what remains of the input buffer after inflation. This +means that C<$buffer> will be an empty string when the return status is +C. When the return status is C the C<$buffer> +parameter will contains what (if anything) was stored in the input +buffer after the deflated data stream. + +This feature is useful when processing a file format that encapsulates +a compressed data stream (e.g. gzip, zip). + +=head2 B<$status = $i-EinflateSync($buffer)> + +Scans C<$buffer> until it reaches either a I or the +end of the buffer. + +If a I is found, C is returned and C<$buffer> +will be have all data up to the flush point removed. This can then be +passed to the C method. + +Any other return code means that a flush point was not found. If more +data is available, C can be called repeatedly with more +compressed data until the flush point is found. + +=head2 B<$i-Edict_adler()> + +Returns the adler32 value for the dictionary. + +=head2 B<$i-Emsg()> + +Returns the last error message generated by zlib. + +=head2 B<$i-Etotal_in()> + +Returns the total number of bytes compressed bytes input to inflate. + +=head2 B<$i-Etotal_out()> + +Returns the total number of uncompressed bytes output from inflate. + +=head2 Example + +Here is an example of using C. + + use strict ; + use warnings ; + + use Compress::Zlib ; + + my $x = inflateInit() + or die "Cannot create a inflation stream\n" ; + + my $input = '' ; + binmode STDIN; + binmode STDOUT; + + my ($output, $status) ; + while (read(STDIN, $input, 4096)) + { + ($output, $status) = $x->inflate(\$input) ; + + print $output + if $status == Z_OK or $status == Z_STREAM_END ; + + last if $status != Z_OK ; + } + + die "inflation failed\n" + unless $status == Z_STREAM_END ; + +=head1 CHECKSUM FUNCTIONS + +Two functions are provided by I to calculate checksums. For the +Perl interface, the order of the two parameters in both functions has +been reversed. This allows both running checksums and one off +calculations to be done. + + $crc = adler32($buffer [,$crc]) ; + $crc = crc32($buffer [,$crc]) ; + +The buffer parameters can either be a scalar or a scalar reference. + +If the $crc parameters is C, the crc value will be reset. + +If you have built this module with zlib 1.2.3 or better, two more +CRC-related functions are available. + + $crc = adler32_combine($crc1, $crc2, $len2)l + $crc = crc32_combine($adler1, $adler2, $len2) + +These functions allow checksums to be merged. + +=head1 Misc + +=head2 my $version = Compress::Zlib::zlib_version(); + +Returns the version of the zlib library. + +=head1 CONSTANTS + +All the I constants are automatically imported when you make use +of I. + +=head1 SEE ALSO + +L, L, L, L, L, L, L, L, L, L, L, L, L, L + +L + +L, L, +L, +L + +For RFC 1950, 1951 and 1952 see +F, +F and +F + +The I compression library was written by Jean-loup Gailly +F and Mark Adler F. + +The primary site for the I compression library is +F. + +The primary site for gzip is F. + +=head1 AUTHOR + +This module was written by Paul Marquess, F. + +=head1 MODIFICATION HISTORY + +See the Changes file. + +=head1 COPYRIGHT AND LICENSE + +Copyright (c) 1995-2009 Paul Marquess. All rights reserved. + +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + diff --git a/ext/IO-Compress/lib/File/GlobMapper.pm b/ext/IO-Compress/lib/File/GlobMapper.pm new file mode 100644 index 0000000000..40a606309e --- /dev/null +++ b/ext/IO-Compress/lib/File/GlobMapper.pm @@ -0,0 +1,679 @@ +package File::GlobMapper; + +use strict; +use warnings; +use Carp; + +our ($CSH_GLOB); + +BEGIN +{ + if ($] < 5.006) + { + require File::BSDGlob; import File::BSDGlob qw(:glob) ; + $CSH_GLOB = File::BSDGlob::GLOB_CSH() ; + *globber = \&File::BSDGlob::csh_glob; + } + else + { + require File::Glob; import File::Glob qw(:glob) ; + $CSH_GLOB = File::Glob::GLOB_CSH() ; + #*globber = \&File::Glob::bsd_glob; + *globber = \&File::Glob::csh_glob; + } +} + +our ($Error); + +our ($VERSION, @EXPORT_OK); +$VERSION = '1.000'; +@EXPORT_OK = qw( globmap ); + + +our ($noPreBS, $metachars, $matchMetaRE, %mapping, %wildCount); +$noPreBS = '(? '([^/]*)', + '?' => '([^/])', + '.' => '\.', + '[' => '([', + '(' => '(', + ')' => ')', + ); + +%wildCount = map { $_ => 1 } qw/ * ? . { ( [ /; + +sub globmap ($$;) +{ + my $inputGlob = shift ; + my $outputGlob = shift ; + + my $obj = new File::GlobMapper($inputGlob, $outputGlob, @_) + or croak "globmap: $Error" ; + return $obj->getFileMap(); +} + +sub new +{ + my $class = shift ; + my $inputGlob = shift ; + my $outputGlob = shift ; + # TODO -- flags needs to default to whatever File::Glob does + my $flags = shift || $CSH_GLOB ; + #my $flags = shift ; + + $inputGlob =~ s/^\s*\<\s*//; + $inputGlob =~ s/\s*\>\s*$//; + + $outputGlob =~ s/^\s*\<\s*//; + $outputGlob =~ s/\s*\>\s*$//; + + my %object = + ( InputGlob => $inputGlob, + OutputGlob => $outputGlob, + GlobFlags => $flags, + Braces => 0, + WildCount => 0, + Pairs => [], + Sigil => '#', + ); + + my $self = bless \%object, ref($class) || $class ; + + $self->_parseInputGlob() + or return undef ; + + $self->_parseOutputGlob() + or return undef ; + + my @inputFiles = globber($self->{InputGlob}, $flags) ; + + if (GLOB_ERROR) + { + $Error = $!; + return undef ; + } + + #if (whatever) + { + my $missing = grep { ! -e $_ } @inputFiles ; + + if ($missing) + { + $Error = "$missing input files do not exist"; + return undef ; + } + } + + $self->{InputFiles} = \@inputFiles ; + + $self->_getFiles() + or return undef ; + + return $self; +} + +sub _retError +{ + my $string = shift ; + $Error = "$string in input fileglob" ; + return undef ; +} + +sub _unmatched +{ + my $delimeter = shift ; + + _retError("Unmatched $delimeter"); + return undef ; +} + +sub _parseBit +{ + my $self = shift ; + + my $string = shift ; + + my $out = ''; + my $depth = 0 ; + + while ($string =~ s/(.*?)$noPreBS(,|$matchMetaRE)//) + { + $out .= quotemeta($1) ; + $out .= $mapping{$2} if defined $mapping{$2}; + + ++ $self->{WildCount} if $wildCount{$2} ; + + if ($2 eq ',') + { + return _unmatched "(" + if $depth ; + + $out .= '|'; + } + elsif ($2 eq '(') + { + ++ $depth ; + } + elsif ($2 eq ')') + { + return _unmatched ")" + if ! $depth ; + + -- $depth ; + } + elsif ($2 eq '[') + { + # TODO -- quotemeta & check no '/' + # TODO -- check for \] & other \ within the [] + $string =~ s#(.*?\])## + or return _unmatched "[" ; + $out .= "$1)" ; + } + elsif ($2 eq ']') + { + return _unmatched "]" ; + } + elsif ($2 eq '{' || $2 eq '}') + { + return _retError "Nested {} not allowed" ; + } + } + + $out .= quotemeta $string; + + return _unmatched "(" + if $depth ; + + return $out ; +} + +sub _parseInputGlob +{ + my $self = shift ; + + my $string = $self->{InputGlob} ; + my $inGlob = ''; + + # Multiple concatenated *'s don't make sense + #$string =~ s#\*\*+#*# ; + + # TODO -- Allow space to delimit patterns? + #my @strings = split /\s+/, $string ; + #for my $str (@strings) + my $out = ''; + my $depth = 0 ; + + while ($string =~ s/(.*?)$noPreBS($matchMetaRE)//) + { + $out .= quotemeta($1) ; + $out .= $mapping{$2} if defined $mapping{$2}; + ++ $self->{WildCount} if $wildCount{$2} ; + + if ($2 eq '(') + { + ++ $depth ; + } + elsif ($2 eq ')') + { + return _unmatched ")" + if ! $depth ; + + -- $depth ; + } + elsif ($2 eq '[') + { + # TODO -- quotemeta & check no '/' or '(' or ')' + # TODO -- check for \] & other \ within the [] + $string =~ s#(.*?\])## + or return _unmatched "["; + $out .= "$1)" ; + } + elsif ($2 eq ']') + { + return _unmatched "]" ; + } + elsif ($2 eq '}') + { + return _unmatched "}" ; + } + elsif ($2 eq '{') + { + # TODO -- check no '/' within the {} + # TODO -- check for \} & other \ within the {} + + my $tmp ; + unless ( $string =~ s/(.*?)$noPreBS\}//) + { + return _unmatched "{"; + } + #$string =~ s#(.*?)\}##; + + #my $alt = join '|', + # map { quotemeta $_ } + # split "$noPreBS,", $1 ; + my $alt = $self->_parseBit($1); + defined $alt or return 0 ; + $out .= "($alt)" ; + + ++ $self->{Braces} ; + } + } + + return _unmatched "(" + if $depth ; + + $out .= quotemeta $string ; + + + $self->{InputGlob} =~ s/$noPreBS[\(\)]//g; + $self->{InputPattern} = $out ; + + #print "# INPUT '$self->{InputGlob}' => '$out'\n"; + + return 1 ; + +} + +sub _parseOutputGlob +{ + my $self = shift ; + + my $string = $self->{OutputGlob} ; + my $maxwild = $self->{WildCount}; + + if ($self->{GlobFlags} & GLOB_TILDE) + #if (1) + { + $string =~ s{ + ^ ~ # find a leading tilde + ( # save this in $1 + [^/] # a non-slash character + * # repeated 0 or more times (0 means me) + ) + }{ + $1 + ? (getpwnam($1))[7] + : ( $ENV{HOME} || $ENV{LOGDIR} ) + }ex; + + } + + # max #1 must be == to max no of '*' in input + while ( $string =~ m/#(\d)/g ) + { + croak "Max wild is #$maxwild, you tried #$1" + if $1 > $maxwild ; + } + + my $noPreBS = '(?{OutputGlob}' => '$string'\n"; + $self->{OutputPattern} = $string ; + + return 1 ; +} + +sub _getFiles +{ + my $self = shift ; + + my %outInMapping = (); + my %inFiles = () ; + + foreach my $inFile (@{ $self->{InputFiles} }) + { + next if $inFiles{$inFile} ++ ; + + my $outFile = $inFile ; + + if ( $inFile =~ m/$self->{InputPattern}/ ) + { + no warnings 'uninitialized'; + eval "\$outFile = $self->{OutputPattern};" ; + + if (defined $outInMapping{$outFile}) + { + $Error = "multiple input files map to one output file"; + return undef ; + } + $outInMapping{$outFile} = $inFile; + push @{ $self->{Pairs} }, [$inFile, $outFile]; + } + } + + return 1 ; +} + +sub getFileMap +{ + my $self = shift ; + + return $self->{Pairs} ; +} + +sub getHash +{ + my $self = shift ; + + return { map { $_->[0] => $_->[1] } @{ $self->{Pairs} } } ; +} + +1; + +__END__ + +=head1 NAME + +File::GlobMapper - Extend File Glob to Allow Input and Output Files + +=head1 SYNOPSIS + + use File::GlobMapper qw( globmap ); + + my $aref = globmap $input => $output + or die $File::GlobMapper::Error ; + + my $gm = new File::GlobMapper $input => $output + or die $File::GlobMapper::Error ; + + +=head1 DESCRIPTION + +This module needs Perl5.005 or better. + +This module takes the existing C module as a starting point and +extends it to allow new filenames to be derived from the files matched by +C. + +This can be useful when carrying out batch operations on multiple files that +have both an input filename and output filename and the output file can be +derived from the input filename. Examples of operations where this can be +useful include, file renaming, file copying and file compression. + + +=head2 Behind The Scenes + +To help explain what C does, consider what code you +would write if you wanted to rename all files in the current directory +that ended in C<.tar.gz> to C<.tgz>. So say these files are in the +current directory + + alpha.tar.gz + beta.tar.gz + gamma.tar.gz + +and they need renamed to this + + alpha.tgz + beta.tgz + gamma.tgz + +Below is a possible implementation of a script to carry out the rename +(error cases have been omitted) + + foreach my $old ( glob "*.tar.gz" ) + { + my $new = $old; + $new =~ s#(.*)\.tar\.gz$#$1.tgz# ; + + rename $old => $new + or die "Cannot rename '$old' to '$new': $!\n; + } + +Notice that a file glob pattern C<*.tar.gz> was used to match the +C<.tar.gz> files, then a fairly similar regular expression was used in +the substitute to allow the new filename to be created. + +Given that the file glob is just a cut-down regular expression and that it +has already done a lot of the hard work in pattern matching the filenames, +wouldn't it be handy to be able to use the patterns in the fileglob to +drive the new filename? + +Well, that's I what C does. + +Here is same snippet of code rewritten using C + + for my $pair (globmap '<*.tar.gz>' => '<#1.tgz>' ) + { + my ($from, $to) = @$pair; + rename $from => $to + or die "Cannot rename '$old' to '$new': $!\n; + } + +So how does it work? + +Behind the scenes the C function does a combination of a +file glob to match existing filenames followed by a substitute +to create the new filenames. + +Notice how both parameters to C are strings that are delimited by <>. +This is done to make them look more like file globs - it is just syntactic +sugar, but it can be handy when you want the strings to be visually +distinctive. The enclosing <> are optional, so you don't have to use them - in +fact the first thing globmap will do is remove these delimiters if they are +present. + +The first parameter to C, C<*.tar.gz>, is an I. +Once the enclosing "< ... >" is removed, this is passed (more or +less) unchanged to C to carry out a file match. + +Next the fileglob C<*.tar.gz> is transformed behind the scenes into a +full Perl regular expression, with the additional step of wrapping each +transformed wildcard metacharacter sequence in parenthesis. + +In this case the input fileglob C<*.tar.gz> will be transformed into +this Perl regular expression + + ([^/]*)\.tar\.gz + +Wrapping with parenthesis allows the wildcard parts of the Input File +Glob to be referenced by the second parameter to C, C<#1.tgz>, +the I. This parameter operates just like the replacement +part of a substitute command. The difference is that the C<#1> syntax +is used to reference sub-patterns matched in the input fileglob, rather +than the C<$1> syntax that is used with perl regular expressions. In +this case C<#1> is used to refer to the text matched by the C<*> in the +Input File Glob. This makes it easier to use this module where the +parameters to C are typed at the command line. + +The final step involves passing each filename matched by the C<*.tar.gz> +file glob through the derived Perl regular expression in turn and +expanding the output fileglob using it. + +The end result of all this is a list of pairs of filenames. By default +that is what is returned by C. In this example the data structure +returned will look like this + + ( ['alpha.tar.gz' => 'alpha.tgz'], + ['beta.tar.gz' => 'beta.tgz' ], + ['gamma.tar.gz' => 'gamma.tgz'] + ) + + +Each pair is an array reference with two elements - namely the I +filename, that C has matched, and a I filename that is +derived from the I filename. + + + +=head2 Limitations + +C has been kept simple deliberately, so it isn't intended to +solve all filename mapping operations. Under the hood C (or for +older versions of Perl, C) is used to match the files, so you +will never have the flexibility of full Perl regular expression. + +=head2 Input File Glob + +The syntax for an Input FileGlob is identical to C, except +for the following + +=over 5 + +=item 1. + +No nested {} + +=item 2. + +Whitespace does not delimit fileglobs. + +=item 3. + +The use of parenthesis can be used to capture parts of the input filename. + +=item 4. + +If an Input glob matches the same file more than once, only the first +will be used. + +=back + +The syntax + +=over 5 + +=item B<~> + +=item B<~user> + + +=item B<.> + +Matches a literal '.'. +Equivalent to the Perl regular expression + + \. + +=item B<*> + +Matches zero or more characters, except '/'. Equivalent to the Perl +regular expression + + [^/]* + +=item B + +Matches zero or one character, except '/'. Equivalent to the Perl +regular expression + + [^/]? + +=item B<\> + +Backslash is used, as usual, to escape the next character. + +=item B<[]> + +Character class. + +=item B<{,}> + +Alternation + +=item B<()> + +Capturing parenthesis that work just like perl + +=back + +Any other character it taken literally. + +=head2 Output File Glob + +The Output File Glob is a normal string, with 2 glob-like features. + +The first is the '*' metacharacter. This will be replaced by the complete +filename matched by the input file glob. So + + *.c *.Z + +The second is + +Output FileGlobs take the + +=over 5 + +=item "*" + +The "*" character will be replaced with the complete input filename. + +=item #1 + +Patterns of the form /#\d/ will be replaced with the + +=back + +=head2 Returned Data + + +=head1 EXAMPLES + +=head2 A Rename script + +Below is a simple "rename" script that uses C to determine the +source and destination filenames. + + use File::GlobMapper qw(globmap) ; + use File::Copy; + + die "rename: Usage rename 'from' 'to'\n" + unless @ARGV == 2 ; + + my $fromGlob = shift @ARGV; + my $toGlob = shift @ARGV; + + my $pairs = globmap($fromGlob, $toGlob) + or die $File::GlobMapper::Error; + + for my $pair (@$pairs) + { + my ($from, $to) = @$pair; + move $from => $to ; + } + + + +Here is an example that renames all c files to cpp. + + $ rename '*.c' '#1.cpp' + +=head2 A few example globmaps + +Below are a few examples of globmaps + +To copy all your .c file to a backup directory + + '' '' + +If you want to compress all + + '' '<*.gz>' + +To uncompress + + '' '' + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +The I module was written by Paul Marquess, F. + +=head1 COPYRIGHT AND LICENSE + +Copyright (c) 2005 Paul Marquess. All rights reserved. +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. diff --git a/ext/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm b/ext/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm new file mode 100644 index 0000000000..7e6b0199b4 --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm @@ -0,0 +1,162 @@ +package IO::Compress::Adapter::Bzip2 ; + +use strict; +use warnings; +use bytes; + +use IO::Compress::Base::Common 2.016 qw(:Status); + +#use Compress::Bzip2 ; +use Compress::Raw::Bzip2 2.016 ; + +our ($VERSION); +$VERSION = '2.016'; + +sub mkCompObject +{ + my $BlockSize100K = shift ; + my $WorkFactor = shift ; + my $Verbosity = shift ; + + my ($def, $status) = new Compress::Raw::Bzip2(1, $BlockSize100K, + $WorkFactor, $Verbosity); + #my ($def, $status) = bzdeflateInit(); + #-BlockSize100K => $params->value('BlockSize100K'), + #-WorkFactor => $params->value('WorkFactor'); + + return (undef, "Could not create Deflate object: $status", $status) + if $status != BZ_OK ; + + return bless {'Def' => $def, + 'Error' => '', + 'ErrorNo' => 0, + } ; +} + +sub compr +{ + my $self = shift ; + + my $def = $self->{Def}; + + #my ($out, $status) = $def->bzdeflate(defined ${$_[0]} ? ${$_[0]} : "") ; + my $status = $def->bzdeflate($_[0], $_[1]) ; + $self->{ErrorNo} = $status; + + if ($status != BZ_RUN_OK) + { + $self->{Error} = "Deflate Error: $status"; + return STATUS_ERROR; + } + + #${ $_[1] } .= $out if defined $out; + + return STATUS_OK; +} + +sub flush +{ + my $self = shift ; + + my $def = $self->{Def}; + + #my ($out, $status) = $def->bzflush($opt); + #my $status = $def->bzflush($_[0], $opt); + my $status = $def->bzflush($_[0]); + $self->{ErrorNo} = $status; + + if ($status != BZ_RUN_OK) + { + $self->{Error} = "Deflate Error: $status"; + return STATUS_ERROR; + } + + #${ $_[0] } .= $out if defined $out ; + return STATUS_OK; + +} + +sub close +{ + my $self = shift ; + + my $def = $self->{Def}; + + #my ($out, $status) = $def->bzclose(); + my $status = $def->bzclose($_[0]); + $self->{ErrorNo} = $status; + + if ($status != BZ_STREAM_END) + { + $self->{Error} = "Deflate Error: $status"; + return STATUS_ERROR; + } + + #${ $_[0] } .= $out if defined $out ; + return STATUS_OK; + +} + + +sub reset +{ + my $self = shift ; + + my $outer = $self->{Outer}; + + my ($def, $status) = new Compress::Raw::Bzip2(); + $self->{ErrorNo} = ($status == BZ_OK) ? 0 : $status ; + + if ($status != BZ_OK) + { + $self->{Error} = "Cannot create Deflate object: $status"; + return STATUS_ERROR; + } + + $self->{Def} = $def; + + return STATUS_OK; +} + +sub compressedBytes +{ + my $self = shift ; + $self->{Def}->compressedBytes(); +} + +sub uncompressedBytes +{ + my $self = shift ; + $self->{Def}->uncompressedBytes(); +} + +#sub total_out +#{ +# my $self = shift ; +# 0; +#} +# + +#sub total_in +#{ +# my $self = shift ; +# $self->{Def}->total_in(); +#} +# +#sub crc32 +#{ +# my $self = shift ; +# $self->{Def}->crc32(); +#} +# +#sub adler32 +#{ +# my $self = shift ; +# $self->{Def}->adler32(); +#} + + +1; + +__END__ + diff --git a/ext/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm b/ext/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm new file mode 100644 index 0000000000..bbd0ed5ad7 --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm @@ -0,0 +1,165 @@ +package IO::Compress::Adapter::Deflate ; + +use strict; +use warnings; +use bytes; + +use IO::Compress::Base::Common 2.017 qw(:Status); + +use Compress::Raw::Zlib 2.017 qw(Z_OK Z_FINISH MAX_WBITS) ; +our ($VERSION); + +$VERSION = '2.017'; + +sub mkCompObject +{ + my $crc32 = shift ; + my $adler32 = shift ; + my $level = shift ; + my $strategy = shift ; + + my ($def, $status) = new Compress::Raw::Zlib::Deflate + -AppendOutput => 1, + -CRC32 => $crc32, + -ADLER32 => $adler32, + -Level => $level, + -Strategy => $strategy, + -WindowBits => - MAX_WBITS; + + return (undef, "Cannot create Deflate object: $status", $status) + if $status != Z_OK; + + return bless {'Def' => $def, + 'Error' => '', + } ; +} + +sub compr +{ + my $self = shift ; + + my $def = $self->{Def}; + + my $status = $def->deflate($_[0], $_[1]) ; + $self->{ErrorNo} = $status; + + if ($status != Z_OK) + { + $self->{Error} = "Deflate Error: $status"; + return STATUS_ERROR; + } + + return STATUS_OK; +} + +sub flush +{ + my $self = shift ; + + my $def = $self->{Def}; + + my $opt = $_[1] || Z_FINISH; + my $status = $def->flush($_[0], $opt); + $self->{ErrorNo} = $status; + + if ($status != Z_OK) + { + $self->{Error} = "Deflate Error: $status"; + return STATUS_ERROR; + } + + return STATUS_OK; + +} + +sub close +{ + my $self = shift ; + + my $def = $self->{Def}; + + $def->flush($_[0], Z_FINISH) + if defined $def ; +} + +sub reset +{ + my $self = shift ; + + my $def = $self->{Def}; + + my $status = $def->deflateReset() ; + $self->{ErrorNo} = $status; + if ($status != Z_OK) + { + $self->{Error} = "Deflate Error: $status"; + return STATUS_ERROR; + } + + return STATUS_OK; +} + +sub deflateParams +{ + my $self = shift ; + + my $def = $self->{Def}; + + my $status = $def->deflateParams(@_); + $self->{ErrorNo} = $status; + if ($status != Z_OK) + { + $self->{Error} = "deflateParams Error: $status"; + return STATUS_ERROR; + } + + return STATUS_OK; +} + + + +#sub total_out +#{ +# my $self = shift ; +# $self->{Def}->total_out(); +#} +# +#sub total_in +#{ +# my $self = shift ; +# $self->{Def}->total_in(); +#} + +sub compressedBytes +{ + my $self = shift ; + + $self->{Def}->compressedBytes(); +} + +sub uncompressedBytes +{ + my $self = shift ; + $self->{Def}->uncompressedBytes(); +} + + + + +sub crc32 +{ + my $self = shift ; + $self->{Def}->crc32(); +} + +sub adler32 +{ + my $self = shift ; + $self->{Def}->adler32(); +} + + +1; + +__END__ + diff --git a/ext/IO-Compress/lib/IO/Compress/Adapter/Identity.pm b/ext/IO-Compress/lib/IO/Compress/Adapter/Identity.pm new file mode 100644 index 0000000000..e6f33a3612 --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Adapter/Identity.pm @@ -0,0 +1,101 @@ +package IO::Compress::Adapter::Identity ; + +use strict; +use warnings; +use bytes; + +use IO::Compress::Base::Common 2.017 qw(:Status); +our ($VERSION); + +$VERSION = '2.017'; + +sub mkCompObject +{ + my $level = shift ; + my $strategy = shift ; + + return bless { + 'CompSize' => 0, + 'UnCompSize' => 0, + 'Error' => '', + 'ErrorNo' => 0, + } ; +} + +sub compr +{ + my $self = shift ; + + if (defined ${ $_[0] } && length ${ $_[0] }) { + $self->{CompSize} += length ${ $_[0] } ; + $self->{UnCompSize} = $self->{CompSize} ; + + if ( ref $_[1] ) + { ${ $_[1] } .= ${ $_[0] } } + else + { $_[1] .= ${ $_[0] } } + } + + return STATUS_OK ; +} + +sub flush +{ + my $self = shift ; + + return STATUS_OK; +} + +sub close +{ + my $self = shift ; + + return STATUS_OK; +} + +sub reset +{ + my $self = shift ; + + $self->{CompSize} = 0; + $self->{UnCompSize} = 0; + + return STATUS_OK; +} + +sub deflateParams +{ + my $self = shift ; + + return STATUS_OK; +} + +#sub total_out +#{ +# my $self = shift ; +# return $self->{UnCompSize} ; +#} +# +#sub total_in +#{ +# my $self = shift ; +# return $self->{UnCompSize} ; +#} + +sub compressedBytes +{ + my $self = shift ; + return $self->{UnCompSize} ; +} + +sub uncompressedBytes +{ + my $self = shift ; + return $self->{UnCompSize} ; +} + +1; + + +__END__ + diff --git a/ext/IO-Compress/lib/IO/Compress/Base.pm b/ext/IO-Compress/lib/IO/Compress/Base.pm new file mode 100644 index 0000000000..7d00becc11 --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Base.pm @@ -0,0 +1,981 @@ + +package IO::Compress::Base ; + +require 5.004 ; + +use strict ; +use warnings; + +use IO::Compress::Base::Common 2.017 ; + +use IO::File ; +use Scalar::Util qw(blessed readonly); + +#use File::Glob; +#require Exporter ; +use Carp ; +use Symbol; +use bytes; + +our (@ISA, $VERSION); +@ISA = qw(Exporter IO::File); + +$VERSION = '2.017'; + +#Can't locate object method "SWASHNEW" via package "utf8" (perhaps you forgot to load "utf8"?) at .../ext/Compress-Zlib/Gzip/blib/lib/Compress/Zlib/Common.pm line 16. + +sub saveStatus +{ + my $self = shift ; + ${ *$self->{ErrorNo} } = shift() + 0 ; + ${ *$self->{Error} } = '' ; + + return ${ *$self->{ErrorNo} } ; +} + + +sub saveErrorString +{ + my $self = shift ; + my $retval = shift ; + ${ *$self->{Error} } = shift ; + ${ *$self->{ErrorNo} } = shift() + 0 if @_ ; + + return $retval; +} + +sub croakError +{ + my $self = shift ; + $self->saveErrorString(0, $_[0]); + croak $_[0]; +} + +sub closeError +{ + my $self = shift ; + my $retval = shift ; + + my $errno = *$self->{ErrorNo}; + my $error = ${ *$self->{Error} }; + + $self->close(); + + *$self->{ErrorNo} = $errno ; + ${ *$self->{Error} } = $error ; + + return $retval; +} + + + +sub error +{ + my $self = shift ; + return ${ *$self->{Error} } ; +} + +sub errorNo +{ + my $self = shift ; + return ${ *$self->{ErrorNo} } ; +} + + +sub writeAt +{ + my $self = shift ; + my $offset = shift; + my $data = shift; + + if (defined *$self->{FH}) { + my $here = tell(*$self->{FH}); + return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) + if $here < 0 ; + seek(*$self->{FH}, $offset, SEEK_SET) + or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ; + defined *$self->{FH}->write($data, length $data) + or return $self->saveErrorString(undef, $!, $!) ; + seek(*$self->{FH}, $here, SEEK_SET) + or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ; + } + else { + substr(${ *$self->{Buffer} }, $offset, length($data)) = $data ; + } + + return 1; +} + +sub output +{ + my $self = shift ; + my $data = shift ; + my $last = shift ; + + return 1 + if length $data == 0 && ! $last ; + + if ( *$self->{FilterEnvelope} ) { + *_ = \$data; + &{ *$self->{FilterEnvelope} }(); + } + + if (length $data) { + if ( defined *$self->{FH} ) { + defined *$self->{FH}->write( $data, length $data ) + or return $self->saveErrorString(0, $!, $!); + } + else { + ${ *$self->{Buffer} } .= $data ; + } + } + + return 1; +} + +sub getOneShotParams +{ + return ( 'MultiStream' => [1, 1, Parse_boolean, 1], + ); +} + +sub checkParams +{ + my $self = shift ; + my $class = shift ; + + my $got = shift || IO::Compress::Base::Parameters::new(); + + $got->parse( + { + # Generic Parameters + 'AutoClose' => [1, 1, Parse_boolean, 0], + #'Encode' => [1, 1, Parse_any, undef], + 'Strict' => [0, 1, Parse_boolean, 1], + 'Append' => [1, 1, Parse_boolean, 0], + 'BinModeIn' => [1, 1, Parse_boolean, 0], + + 'FilterEnvelope' => [1, 1, Parse_any, undef], + + $self->getExtraParams(), + *$self->{OneShot} ? $self->getOneShotParams() + : (), + }, + @_) or $self->croakError("${class}: $got->{Error}") ; + + return $got ; +} + +sub _create +{ + my $obj = shift; + my $got = shift; + + *$obj->{Closed} = 1 ; + + my $class = ref $obj; + $obj->croakError("$class: Missing Output parameter") + if ! @_ && ! $got ; + + my $outValue = shift ; + my $oneShot = 1 ; + + if (! $got) + { + $oneShot = 0 ; + $got = $obj->checkParams($class, undef, @_) + or return undef ; + } + + my $lax = ! $got->value('Strict') ; + + my $outType = whatIsOutput($outValue); + + $obj->ckOutputParam($class, $outValue) + or return undef ; + + if ($outType eq 'buffer') { + *$obj->{Buffer} = $outValue; + } + else { + my $buff = "" ; + *$obj->{Buffer} = \$buff ; + } + + # Merge implies Append + my $merge = $got->value('Merge') ; + my $appendOutput = $got->value('Append') || $merge ; + *$obj->{Append} = $appendOutput; + *$obj->{FilterEnvelope} = $got->value('FilterEnvelope') ; + + if ($merge) + { + # Switch off Merge mode if output file/buffer is empty/doesn't exist + if (($outType eq 'buffer' && length $$outValue == 0 ) || + ($outType ne 'buffer' && (! -e $outValue || (-w _ && -z _))) ) + { $merge = 0 } + } + + # If output is a file, check that it is writable + #no warnings; + #if ($outType eq 'filename' && -e $outValue && ! -w _) + # { return $obj->saveErrorString(undef, "Output file '$outValue' is not writable" ) } + + + + if ($got->parsed('Encode')) { + my $want_encoding = $got->value('Encode'); + *$obj->{Encoding} = getEncoding($obj, $class, $want_encoding); + } + + $obj->ckParams($got) + or $obj->croakError("${class}: " . $obj->error()); + + + $obj->saveStatus(STATUS_OK) ; + + my $status ; + if (! $merge) + { + *$obj->{Compress} = $obj->mkComp($got) + or return undef; + + *$obj->{UnCompSize} = new U64 ; + *$obj->{CompSize} = new U64 ; + + if ( $outType eq 'buffer') { + ${ *$obj->{Buffer} } = '' + unless $appendOutput ; + } + else { + if ($outType eq 'handle') { + *$obj->{FH} = $outValue ; + setBinModeOutput(*$obj->{FH}) ; + $outValue->flush() ; + *$obj->{Handle} = 1 ; + if ($appendOutput) + { + seek(*$obj->{FH}, 0, SEEK_END) + or return $obj->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ; + + } + } + elsif ($outType eq 'filename') { + no warnings; + my $mode = '>' ; + $mode = '>>' + if $appendOutput; + *$obj->{FH} = new IO::File "$mode $outValue" + or return $obj->saveErrorString(undef, "cannot open file '$outValue': $!", $!) ; + *$obj->{StdIO} = ($outValue eq '-'); + setBinModeOutput(*$obj->{FH}) ; + } + } + + *$obj->{Header} = $obj->mkHeader($got) ; + $obj->output( *$obj->{Header} ) + or return undef; + } + else + { + *$obj->{Compress} = $obj->createMerge($outValue, $outType) + or return undef; + } + + *$obj->{Closed} = 0 ; + *$obj->{AutoClose} = $got->value('AutoClose') ; + *$obj->{Output} = $outValue; + *$obj->{ClassName} = $class; + *$obj->{Got} = $got; + *$obj->{OneShot} = 0 ; + + return $obj ; +} + +sub ckOutputParam +{ + my $self = shift ; + my $from = shift ; + my $outType = whatIsOutput($_[0]); + + $self->croakError("$from: output parameter not a filename, filehandle or scalar ref") + if ! $outType ; + + #$self->croakError("$from: output filename is undef or null string") + #if $outType eq 'filename' && (! defined $_[0] || $_[0] eq '') ; + + $self->croakError("$from: output buffer is read-only") + if $outType eq 'buffer' && readonly(${ $_[0] }); + + return 1; +} + + +sub _def +{ + my $obj = shift ; + + my $class= (caller)[0] ; + my $name = (caller(1))[3] ; + + $obj->croakError("$name: expected at least 1 parameters\n") + unless @_ >= 1 ; + + my $input = shift ; + my $haveOut = @_ ; + my $output = shift ; + + my $x = new IO::Compress::Base::Validator($class, *$obj->{Error}, $name, $input, $output) + or return undef ; + + push @_, $output if $haveOut && $x->{Hash}; + + *$obj->{OneShot} = 1 ; + + my $got = $obj->checkParams($name, undef, @_) + or return undef ; + + $x->{Got} = $got ; + +# if ($x->{Hash}) +# { +# while (my($k, $v) = each %$input) +# { +# $v = \$input->{$k} +# unless defined $v ; +# +# $obj->_singleTarget($x, 1, $k, $v, @_) +# or return undef ; +# } +# +# return keys %$input ; +# } + + if ($x->{GlobMap}) + { + $x->{oneInput} = 1 ; + foreach my $pair (@{ $x->{Pairs} }) + { + my ($from, $to) = @$pair ; + $obj->_singleTarget($x, 1, $from, $to, @_) + or return undef ; + } + + return scalar @{ $x->{Pairs} } ; + } + + if (! $x->{oneOutput} ) + { + my $inFile = ($x->{inType} eq 'filenames' + || $x->{inType} eq 'filename'); + + $x->{inType} = $inFile ? 'filename' : 'buffer'; + + foreach my $in ($x->{oneInput} ? $input : @$input) + { + my $out ; + $x->{oneInput} = 1 ; + + $obj->_singleTarget($x, $inFile, $in, \$out, @_) + or return undef ; + + push @$output, \$out ; + #if ($x->{outType} eq 'array') + # { push @$output, \$out } + #else + # { $output->{$in} = \$out } + } + + return 1 ; + } + + # finally the 1 to 1 and n to 1 + return $obj->_singleTarget($x, 1, $input, $output, @_); + + croak "should not be here" ; +} + +sub _singleTarget +{ + my $obj = shift ; + my $x = shift ; + my $inputIsFilename = shift; + my $input = shift; + + if ($x->{oneInput}) + { + $obj->getFileInfo($x->{Got}, $input) + if isaFilename($input) and $inputIsFilename ; + + my $z = $obj->_create($x->{Got}, @_) + or return undef ; + + + defined $z->_wr2($input, $inputIsFilename) + or return $z->closeError(undef) ; + + return $z->close() ; + } + else + { + my $afterFirst = 0 ; + my $inputIsFilename = ($x->{inType} ne 'array'); + my $keep = $x->{Got}->clone(); + + #for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input) + for my $element ( @$input) + { + my $isFilename = isaFilename($element); + + if ( $afterFirst ++ ) + { + defined addInterStream($obj, $element, $isFilename) + or return $obj->closeError(undef) ; + } + else + { + $obj->getFileInfo($x->{Got}, $element) + if $isFilename; + + $obj->_create($x->{Got}, @_) + or return undef ; + } + + defined $obj->_wr2($element, $isFilename) + or return $obj->closeError(undef) ; + + *$obj->{Got} = $keep->clone(); + } + return $obj->close() ; + } + +} + +sub _wr2 +{ + my $self = shift ; + + my $source = shift ; + my $inputIsFilename = shift; + + my $input = $source ; + if (! $inputIsFilename) + { + $input = \$source + if ! ref $source; + } + + if ( ref $input && ref $input eq 'SCALAR' ) + { + return $self->syswrite($input, @_) ; + } + + if ( ! ref $input || isaFilehandle($input)) + { + my $isFilehandle = isaFilehandle($input) ; + + my $fh = $input ; + + if ( ! $isFilehandle ) + { + $fh = new IO::File "<$input" + or return $self->saveErrorString(undef, "cannot open file '$input': $!", $!) ; + } + binmode $fh if *$self->{Got}->valueOrDefault('BinModeIn') ; + + my $status ; + my $buff ; + my $count = 0 ; + while (($status = read($fh, $buff, 16 * 1024)) > 0) { + $count += length $buff; + defined $self->syswrite($buff, @_) + or return undef ; + } + + return $self->saveErrorString(undef, $!, $!) + if $status < 0 ; + + if ( (!$isFilehandle || *$self->{AutoClose}) && $input ne '-') + { + $fh->close() + or return undef ; + } + + return $count ; + } + + croak "Should not be here"; + return undef; +} + +sub addInterStream +{ + my $self = shift ; + my $input = shift ; + my $inputIsFilename = shift ; + + if (*$self->{Got}->value('MultiStream')) + { + $self->getFileInfo(*$self->{Got}, $input) + #if isaFilename($input) and $inputIsFilename ; + if isaFilename($input) ; + + # TODO -- newStream needs to allow gzip/zip header to be modified + return $self->newStream(); + } + elsif (*$self->{Got}->value('AutoFlush')) + { + #return $self->flush(Z_FULL_FLUSH); + } + + return 1 ; +} + +sub getFileInfo +{ +} + +sub TIEHANDLE +{ + return $_[0] if ref($_[0]); + die "OOPS\n" ; +} + +sub UNTIE +{ + my $self = shift ; +} + +sub DESTROY +{ + my $self = shift ; + local ($., $@, $!, $^E, $?); + + $self->close() ; + + # TODO - memory leak with 5.8.0 - this isn't called until + # global destruction + # + %{ *$self } = () ; + undef $self ; +} + + + +sub filterUncompressed +{ +} + +sub syswrite +{ + my $self = shift ; + + my $buffer ; + if (ref $_[0] ) { + $self->croakError( *$self->{ClassName} . "::write: not a scalar reference" ) + unless ref $_[0] eq 'SCALAR' ; + $buffer = $_[0] ; + } + else { + $buffer = \$_[0] ; + } + + $] >= 5.008 and ( utf8::downgrade($$buffer, 1) + or croak "Wide character in " . *$self->{ClassName} . "::write:"); + + + if (@_ > 1) { + my $slen = defined $$buffer ? length($$buffer) : 0; + my $len = $slen; + my $offset = 0; + $len = $_[1] if $_[1] < $len; + + if (@_ > 2) { + $offset = $_[2] || 0; + $self->croakError(*$self->{ClassName} . "::write: offset outside string") + if $offset > $slen; + if ($offset < 0) { + $offset += $slen; + $self->croakError( *$self->{ClassName} . "::write: offset outside string") if $offset < 0; + } + my $rem = $slen - $offset; + $len = $rem if $rem < $len; + } + + $buffer = \substr($$buffer, $offset, $len) ; + } + + return 0 if ! defined $$buffer || length $$buffer == 0 ; + + if (*$self->{Encoding}) { + $$buffer = *$self->{Encoding}->encode($$buffer); + } + + $self->filterUncompressed($buffer); + + my $buffer_length = defined $$buffer ? length($$buffer) : 0 ; + *$self->{UnCompSize}->add($buffer_length) ; + + my $outBuffer=''; + my $status = *$self->{Compress}->compr($buffer, $outBuffer) ; + + return $self->saveErrorString(undef, *$self->{Compress}{Error}, + *$self->{Compress}{ErrorNo}) + if $status == STATUS_ERROR; + + *$self->{CompSize}->add(length $outBuffer) ; + + $self->output($outBuffer) + or return undef; + + return $buffer_length; +} + +sub print +{ + my $self = shift; + + #if (ref $self) { + # $self = *$self{GLOB} ; + #} + + if (defined $\) { + if (defined $,) { + defined $self->syswrite(join($,, @_) . $\); + } else { + defined $self->syswrite(join("", @_) . $\); + } + } else { + if (defined $,) { + defined $self->syswrite(join($,, @_)); + } else { + defined $self->syswrite(join("", @_)); + } + } +} + +sub printf +{ + my $self = shift; + my $fmt = shift; + defined $self->syswrite(sprintf($fmt, @_)); +} + + + +sub flush +{ + my $self = shift ; + + my $outBuffer=''; + my $status = *$self->{Compress}->flush($outBuffer, @_) ; + return $self->saveErrorString(0, *$self->{Compress}{Error}, + *$self->{Compress}{ErrorNo}) + if $status == STATUS_ERROR; + + if ( defined *$self->{FH} ) { + *$self->{FH}->clearerr(); + } + + *$self->{CompSize}->add(length $outBuffer) ; + + $self->output($outBuffer) + or return 0; + + if ( defined *$self->{FH} ) { + defined *$self->{FH}->flush() + or return $self->saveErrorString(0, $!, $!); + } + + return 1; +} + +sub newStream +{ + my $self = shift ; + + $self->_writeTrailer() + or return 0 ; + + my $got = $self->checkParams('newStream', *$self->{Got}, @_) + or return 0 ; + + $self->ckParams($got) + or $self->croakError("newStream: $self->{Error}"); + + *$self->{Compress} = $self->mkComp($got) + or return 0; + + *$self->{Header} = $self->mkHeader($got) ; + $self->output(*$self->{Header} ) + or return 0; + + *$self->{UnCompSize}->reset(); + *$self->{CompSize}->reset(); + + return 1 ; +} + +sub reset +{ + my $self = shift ; + return *$self->{Compress}->reset() ; +} + +sub _writeTrailer +{ + my $self = shift ; + + my $trailer = ''; + + my $status = *$self->{Compress}->close($trailer) ; + return $self->saveErrorString(0, *$self->{Compress}{Error}, *$self->{Compress}{ErrorNo}) + if $status == STATUS_ERROR; + + *$self->{CompSize}->add(length $trailer) ; + + $trailer .= $self->mkTrailer(); + defined $trailer + or return 0; + + return $self->output($trailer); +} + +sub _writeFinalTrailer +{ + my $self = shift ; + + return $self->output($self->mkFinalTrailer()); +} + +sub close +{ + my $self = shift ; + + return 1 if *$self->{Closed} || ! *$self->{Compress} ; + *$self->{Closed} = 1 ; + + untie *$self + if $] >= 5.008 ; + + $self->_writeTrailer() + or return 0 ; + + $self->_writeFinalTrailer() + or return 0 ; + + $self->output( "", 1 ) + or return 0; + + if (defined *$self->{FH}) { + + #if (! *$self->{Handle} || *$self->{AutoClose}) { + if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) { + $! = 0 ; + *$self->{FH}->close() + or return $self->saveErrorString(0, $!, $!); + } + delete *$self->{FH} ; + # This delete can set $! in older Perls, so reset the errno + $! = 0 ; + } + + return 1; +} + + +#sub total_in +#sub total_out +#sub msg +# +#sub crc +#{ +# my $self = shift ; +# return *$self->{Compress}->crc32() ; +#} +# +#sub msg +#{ +# my $self = shift ; +# return *$self->{Compress}->msg() ; +#} +# +#sub dict_adler +#{ +# my $self = shift ; +# return *$self->{Compress}->dict_adler() ; +#} +# +#sub get_Level +#{ +# my $self = shift ; +# return *$self->{Compress}->get_Level() ; +#} +# +#sub get_Strategy +#{ +# my $self = shift ; +# return *$self->{Compress}->get_Strategy() ; +#} + + +sub tell +{ + my $self = shift ; + + return *$self->{UnCompSize}->get32bit() ; +} + +sub eof +{ + my $self = shift ; + + return *$self->{Closed} ; +} + + +sub seek +{ + my $self = shift ; + my $position = shift; + my $whence = shift ; + + my $here = $self->tell() ; + my $target = 0 ; + + #use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END); + use IO::Handle ; + + if ($whence == IO::Handle::SEEK_SET) { + $target = $position ; + } + elsif ($whence == IO::Handle::SEEK_CUR || $whence == IO::Handle::SEEK_END) { + $target = $here + $position ; + } + else { + $self->croakError(*$self->{ClassName} . "::seek: unknown value, $whence, for whence parameter"); + } + + # short circuit if seeking to current offset + return 1 if $target == $here ; + + # Outlaw any attempt to seek backwards + $self->croakError(*$self->{ClassName} . "::seek: cannot seek backwards") + if $target < $here ; + + # Walk the file to the new offset + my $offset = $target - $here ; + + my $buffer ; + defined $self->syswrite("\x00" x $offset) + or return 0; + + return 1 ; +} + +sub binmode +{ + 1; +# my $self = shift ; +# return defined *$self->{FH} +# ? binmode *$self->{FH} +# : 1 ; +} + +sub fileno +{ + my $self = shift ; + return defined *$self->{FH} + ? *$self->{FH}->fileno() + : undef ; +} + +sub opened +{ + my $self = shift ; + return ! *$self->{Closed} ; +} + +sub autoflush +{ + my $self = shift ; + return defined *$self->{FH} + ? *$self->{FH}->autoflush(@_) + : undef ; +} + +sub input_line_number +{ + return undef ; +} + + +sub _notAvailable +{ + my $name = shift ; + return sub { croak "$name Not Available: File opened only for output" ; } ; +} + +*read = _notAvailable('read'); +*READ = _notAvailable('read'); +*readline = _notAvailable('readline'); +*READLINE = _notAvailable('readline'); +*getc = _notAvailable('getc'); +*GETC = _notAvailable('getc'); + +*FILENO = \&fileno; +*PRINT = \&print; +*PRINTF = \&printf; +*WRITE = \&syswrite; +*write = \&syswrite; +*SEEK = \&seek; +*TELL = \&tell; +*EOF = \&eof; +*CLOSE = \&close; +*BINMODE = \&binmode; + +#*sysread = \&_notAvailable; +#*syswrite = \&_write; + +1; + +__END__ + +=head1 NAME + +IO::Compress::Base - Base Class for IO::Compress modules + +=head1 SYNOPSIS + + use IO::Compress::Base ; + +=head1 DESCRIPTION + +This module is not intended for direct use in application code. Its sole +purpose if to to be sub-classed by IO::Compress modules. + +=head1 SEE ALSO + +L, L, L, L, L, L, L, L, L, L, L, L, L, L, L + +L + +L, L, +L, +L + +=head1 AUTHOR + +This module was written by Paul Marquess, F. + +=head1 MODIFICATION HISTORY + +See the Changes file. + +=head1 COPYRIGHT AND LICENSE + +Copyright (c) 2005-2009 Paul Marquess. All rights reserved. + +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + diff --git a/ext/IO-Compress/lib/IO/Compress/Base/Common.pm b/ext/IO-Compress/lib/IO/Compress/Base/Common.pm new file mode 100644 index 0000000000..756cf4b38d --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Base/Common.pm @@ -0,0 +1,940 @@ +package IO::Compress::Base::Common; + +use strict ; +use warnings; +use bytes; + +use Carp; +use Scalar::Util qw(blessed readonly); +use File::GlobMapper; + +require Exporter; +our ($VERSION, @ISA, @EXPORT, %EXPORT_TAGS, $HAS_ENCODE); +@ISA = qw(Exporter); +$VERSION = '2.017'; + +@EXPORT = qw( isaFilehandle isaFilename whatIsInput whatIsOutput + isaFileGlobString cleanFileGlobString oneTarget + setBinModeInput setBinModeOutput + ckInOutParams + createSelfTiedObject + getEncoding + + WANT_CODE + WANT_EXT + WANT_UNDEF + WANT_HASH + + STATUS_OK + STATUS_ENDSTREAM + STATUS_EOF + STATUS_ERROR + ); + +%EXPORT_TAGS = ( Status => [qw( STATUS_OK + STATUS_ENDSTREAM + STATUS_EOF + STATUS_ERROR + )]); + + +use constant STATUS_OK => 0; +use constant STATUS_ENDSTREAM => 1; +use constant STATUS_EOF => 2; +use constant STATUS_ERROR => -1; + +sub hasEncode() +{ + if (! defined $HAS_ENCODE) { + eval + { + require Encode; + Encode->import(); + }; + + $HAS_ENCODE = $@ ? 0 : 1 ; + } + + return $HAS_ENCODE; +} + +sub getEncoding($$$) +{ + my $obj = shift; + my $class = shift ; + my $want_encoding = shift ; + + $obj->croakError("$class: Encode module needed to use -Encode") + if ! hasEncode(); + + my $encoding = Encode::find_encoding($want_encoding); + + $obj->croakError("$class: Encoding '$want_encoding' is not available") + if ! $encoding; + + return $encoding; +} + +our ($needBinmode); +$needBinmode = ($^O eq 'MSWin32' || + ($] >= 5.006 && eval ' ${^UNICODE} || ${^UTF8LOCALE} ')) + ? 1 : 1 ; + +sub setBinModeInput($) +{ + my $handle = shift ; + + binmode $handle + if $needBinmode; +} + +sub setBinModeOutput($) +{ + my $handle = shift ; + + binmode $handle + if $needBinmode; +} + +sub isaFilehandle($) +{ + use utf8; # Pragma needed to keep Perl 5.6.0 happy + return (defined $_[0] and + (UNIVERSAL::isa($_[0],'GLOB') or + UNIVERSAL::isa($_[0],'IO::Handle') or + UNIVERSAL::isa(\$_[0],'GLOB')) + ) +} + +sub isaFilename($) +{ + return (defined $_[0] and + ! ref $_[0] and + UNIVERSAL::isa(\$_[0], 'SCALAR')); +} + +sub isaFileGlobString +{ + return defined $_[0] && $_[0] =~ /^<.*>$/; +} + +sub cleanFileGlobString +{ + my $string = shift ; + + $string =~ s/^\s*<\s*(.*)\s*>\s*$/$1/; + + return $string; +} + +use constant WANT_CODE => 1 ; +use constant WANT_EXT => 2 ; +use constant WANT_UNDEF => 4 ; +#use constant WANT_HASH => 8 ; +use constant WANT_HASH => 0 ; + +sub whatIsInput($;$) +{ + my $got = whatIs(@_); + + if (defined $got && $got eq 'filename' && defined $_[0] && $_[0] eq '-') + { + #use IO::File; + $got = 'handle'; + $_[0] = *STDIN; + #$_[0] = new IO::File("<-"); + } + + return $got; +} + +sub whatIsOutput($;$) +{ + my $got = whatIs(@_); + + if (defined $got && $got eq 'filename' && defined $_[0] && $_[0] eq '-') + { + $got = 'handle'; + $_[0] = *STDOUT; + #$_[0] = new IO::File(">-"); + } + + return $got; +} + +sub whatIs ($;$) +{ + return 'handle' if isaFilehandle($_[0]); + + my $wantCode = defined $_[1] && $_[1] & WANT_CODE ; + my $extended = defined $_[1] && $_[1] & WANT_EXT ; + my $undef = defined $_[1] && $_[1] & WANT_UNDEF ; + my $hash = defined $_[1] && $_[1] & WANT_HASH ; + + return 'undef' if ! defined $_[0] && $undef ; + + if (ref $_[0]) { + return '' if blessed($_[0]); # is an object + #return '' if UNIVERSAL::isa($_[0], 'UNIVERSAL'); # is an object + return 'buffer' if UNIVERSAL::isa($_[0], 'SCALAR'); + return 'array' if UNIVERSAL::isa($_[0], 'ARRAY') && $extended ; + return 'hash' if UNIVERSAL::isa($_[0], 'HASH') && $hash ; + return 'code' if UNIVERSAL::isa($_[0], 'CODE') && $wantCode ; + return ''; + } + + return 'fileglob' if $extended && isaFileGlobString($_[0]); + return 'filename'; +} + +sub oneTarget +{ + return $_[0] =~ /^(code|handle|buffer|filename)$/; +} + +sub IO::Compress::Base::Validator::new +{ + my $class = shift ; + + my $Class = shift ; + my $error_ref = shift ; + my $reportClass = shift ; + + my %data = (Class => $Class, + Error => $error_ref, + reportClass => $reportClass, + ) ; + + my $obj = bless \%data, $class ; + + local $Carp::CarpLevel = 1; + + my $inType = $data{inType} = whatIsInput($_[0], WANT_EXT|WANT_HASH); + my $outType = $data{outType} = whatIsOutput($_[1], WANT_EXT|WANT_HASH); + + my $oneInput = $data{oneInput} = oneTarget($inType); + my $oneOutput = $data{oneOutput} = oneTarget($outType); + + if (! $inType) + { + $obj->croakError("$reportClass: illegal input parameter") ; + #return undef ; + } + +# if ($inType eq 'hash') +# { +# $obj->{Hash} = 1 ; +# $obj->{oneInput} = 1 ; +# return $obj->validateHash($_[0]); +# } + + if (! $outType) + { + $obj->croakError("$reportClass: illegal output parameter") ; + #return undef ; + } + + + if ($inType ne 'fileglob' && $outType eq 'fileglob') + { + $obj->croakError("Need input fileglob for outout fileglob"); + } + +# if ($inType ne 'fileglob' && $outType eq 'hash' && $inType ne 'filename' ) +# { +# $obj->croakError("input must ne filename or fileglob when output is a hash"); +# } + + if ($inType eq 'fileglob' && $outType eq 'fileglob') + { + $data{GlobMap} = 1 ; + $data{inType} = $data{outType} = 'filename'; + my $mapper = new File::GlobMapper($_[0], $_[1]); + if ( ! $mapper ) + { + return $obj->saveErrorString($File::GlobMapper::Error) ; + } + $data{Pairs} = $mapper->getFileMap(); + + return $obj; + } + + $obj->croakError("$reportClass: input and output $inType are identical") + if $inType eq $outType && $_[0] eq $_[1] && $_[0] ne '-' ; + + if ($inType eq 'fileglob') # && $outType ne 'fileglob' + { + my $glob = cleanFileGlobString($_[0]); + my @inputs = glob($glob); + + if (@inputs == 0) + { + # TODO -- legal or die? + die "globmap matched zero file -- legal or die???" ; + } + elsif (@inputs == 1) + { + $obj->validateInputFilenames($inputs[0]) + or return undef; + $_[0] = $inputs[0] ; + $data{inType} = 'filename' ; + $data{oneInput} = 1; + } + else + { + $obj->validateInputFilenames(@inputs) + or return undef; + $_[0] = [ @inputs ] ; + $data{inType} = 'filenames' ; + } + } + elsif ($inType eq 'filename') + { + $obj->validateInputFilenames($_[0]) + or return undef; + } + elsif ($inType eq 'array') + { + $data{inType} = 'filenames' ; + $obj->validateInputArray($_[0]) + or return undef ; + } + + return $obj->saveErrorString("$reportClass: output buffer is read-only") + if $outType eq 'buffer' && readonly(${ $_[1] }); + + if ($outType eq 'filename' ) + { + $obj->croakError("$reportClass: output filename is undef or null string") + if ! defined $_[1] || $_[1] eq '' ; + + if (-e $_[1]) + { + if (-d _ ) + { + return $obj->saveErrorString("output file '$_[1]' is a directory"); + } + } + } + + return $obj ; +} + +sub IO::Compress::Base::Validator::saveErrorString +{ + my $self = shift ; + ${ $self->{Error} } = shift ; + return undef; + +} + +sub IO::Compress::Base::Validator::croakError +{ + my $self = shift ; + $self->saveErrorString($_[0]); + croak $_[0]; +} + + + +sub IO::Compress::Base::Validator::validateInputFilenames +{ + my $self = shift ; + + foreach my $filename (@_) + { + $self->croakError("$self->{reportClass}: input filename is undef or null string") + if ! defined $filename || $filename eq '' ; + + next if $filename eq '-'; + + if (! -e $filename ) + { + return $self->saveErrorString("input file '$filename' does not exist"); + } + + if (-d _ ) + { + return $self->saveErrorString("input file '$filename' is a directory"); + } + + if (! -r _ ) + { + return $self->saveErrorString("cannot open file '$filename': $!"); + } + } + + return 1 ; +} + +sub IO::Compress::Base::Validator::validateInputArray +{ + my $self = shift ; + + if ( @{ $_[0] } == 0 ) + { + return $self->saveErrorString("empty array reference") ; + } + + foreach my $element ( @{ $_[0] } ) + { + my $inType = whatIsInput($element); + + if (! $inType) + { + $self->croakError("unknown input parameter") ; + } + elsif($inType eq 'filename') + { + $self->validateInputFilenames($element) + or return undef ; + } + else + { + $self->croakError("not a filename") ; + } + } + + return 1 ; +} + +#sub IO::Compress::Base::Validator::validateHash +#{ +# my $self = shift ; +# my $href = shift ; +# +# while (my($k, $v) = each %$href) +# { +# my $ktype = whatIsInput($k); +# my $vtype = whatIsOutput($v, WANT_EXT|WANT_UNDEF) ; +# +# if ($ktype ne 'filename') +# { +# return $self->saveErrorString("hash key not filename") ; +# } +# +# my %valid = map { $_ => 1 } qw(filename buffer array undef handle) ; +# if (! $valid{$vtype}) +# { +# return $self->saveErrorString("hash value not ok") ; +# } +# } +# +# return $self ; +#} + +sub createSelfTiedObject +{ + my $class = shift || (caller)[0] ; + my $error_ref = shift ; + + my $obj = bless Symbol::gensym(), ref($class) || $class; + tie *$obj, $obj if $] >= 5.005; + *$obj->{Closed} = 1 ; + $$error_ref = ''; + *$obj->{Error} = $error_ref ; + my $errno = 0 ; + *$obj->{ErrorNo} = \$errno ; + + return $obj; +} + + + +#package Parse::Parameters ; +# +# +#require Exporter; +#our ($VERSION, @ISA, @EXPORT); +#$VERSION = '2.000_08'; +#@ISA = qw(Exporter); + +$EXPORT_TAGS{Parse} = [qw( ParseParameters + Parse_any Parse_unsigned Parse_signed + Parse_boolean Parse_custom Parse_string + Parse_multiple Parse_writable_scalar + ) + ]; + +push @EXPORT, @{ $EXPORT_TAGS{Parse} } ; + +use constant Parse_any => 0x01; +use constant Parse_unsigned => 0x02; +use constant Parse_signed => 0x04; +use constant Parse_boolean => 0x08; +use constant Parse_string => 0x10; +use constant Parse_custom => 0x12; + +#use constant Parse_store_ref => 0x100 ; +use constant Parse_multiple => 0x100 ; +use constant Parse_writable => 0x200 ; +use constant Parse_writable_scalar => 0x400 | Parse_writable ; + +use constant OFF_PARSED => 0 ; +use constant OFF_TYPE => 1 ; +use constant OFF_DEFAULT => 2 ; +use constant OFF_FIXED => 3 ; +use constant OFF_FIRST_ONLY => 4 ; +use constant OFF_STICKY => 5 ; + + + +sub ParseParameters +{ + my $level = shift || 0 ; + + my $sub = (caller($level + 1))[3] ; + local $Carp::CarpLevel = 1 ; + + return $_[1] + if @_ == 2 && defined $_[1] && UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters"); + + my $p = new IO::Compress::Base::Parameters() ; + $p->parse(@_) + or croak "$sub: $p->{Error}" ; + + return $p; +} + +#package IO::Compress::Base::Parameters; + +use strict; +use warnings; +use Carp; + +sub IO::Compress::Base::Parameters::new +{ + my $class = shift ; + + my $obj = { Error => '', + Got => {}, + } ; + + #return bless $obj, ref($class) || $class || __PACKAGE__ ; + return bless $obj, 'IO::Compress::Base::Parameters' ; +} + +sub IO::Compress::Base::Parameters::setError +{ + my $self = shift ; + my $error = shift ; + my $retval = @_ ? shift : undef ; + + $self->{Error} = $error ; + return $retval; +} + +#sub getError +#{ +# my $self = shift ; +# return $self->{Error} ; +#} + +sub IO::Compress::Base::Parameters::parse +{ + my $self = shift ; + + my $default = shift ; + + my $got = $self->{Got} ; + my $firstTime = keys %{ $got } == 0 ; + my $other; + + my (@Bad) ; + my @entered = () ; + + # Allow the options to be passed as a hash reference or + # as the complete hash. + if (@_ == 0) { + @entered = () ; + } + elsif (@_ == 1) { + my $href = $_[0] ; + + return $self->setError("Expected even number of parameters, got 1") + if ! defined $href or ! ref $href or ref $href ne "HASH" ; + + foreach my $key (keys %$href) { + push @entered, $key ; + push @entered, \$href->{$key} ; + } + } + else { + my $count = @_; + return $self->setError("Expected even number of parameters, got $count") + if $count % 2 != 0 ; + + for my $i (0.. $count / 2 - 1) { + if ($_[2 * $i] eq '__xxx__') { + $other = $_[2 * $i + 1] ; + } + else { + push @entered, $_[2 * $i] ; + push @entered, \$_[2 * $i + 1] ; + } + } + } + + + while (my ($key, $v) = each %$default) + { + croak "need 4 params [@$v]" + if @$v != 4 ; + + my ($first_only, $sticky, $type, $value) = @$v ; + my $x ; + $self->_checkType($key, \$value, $type, 0, \$x) + or return undef ; + + $key = lc $key; + + if ($firstTime || ! $sticky) { + $x = [ $x ] + if $type & Parse_multiple; + + $got->{$key} = [0, $type, $value, $x, $first_only, $sticky] ; + } + + $got->{$key}[OFF_PARSED] = 0 ; + } + + my %parsed = (); + + if ($other) + { + for my $key (keys %$default) + { + my $canonkey = lc $key; + if ($other->parsed($canonkey)) + { + my $value = $other->value($canonkey); +#print "SET '$canonkey' to $value [$$value]\n"; + ++ $parsed{$canonkey}; + $got->{$canonkey}[OFF_PARSED] = 1; + $got->{$canonkey}[OFF_DEFAULT] = $value; + $got->{$canonkey}[OFF_FIXED] = $value; + } + } + } + + for my $i (0.. @entered / 2 - 1) { + my $key = $entered[2* $i] ; + my $value = $entered[2* $i+1] ; + + #print "Key [$key] Value [$value]" ; + #print defined $$value ? "[$$value]\n" : "[undef]\n"; + + $key =~ s/^-// ; + my $canonkey = lc $key; + + if ($got->{$canonkey} && ($firstTime || + ! $got->{$canonkey}[OFF_FIRST_ONLY] )) + { + my $type = $got->{$canonkey}[OFF_TYPE] ; + my $parsed = $parsed{$canonkey}; + ++ $parsed{$canonkey}; + + return $self->setError("Muliple instances of '$key' found") + if $parsed && $type & Parse_multiple == 0 ; + + my $s ; + $self->_checkType($key, $value, $type, 1, \$s) + or return undef ; + + $value = $$value ; + if ($type & Parse_multiple) { + $got->{$canonkey}[OFF_PARSED] = 1; + push @{ $got->{$canonkey}[OFF_FIXED] }, $s ; + } + else { + $got->{$canonkey} = [1, $type, $value, $s] ; + } + } + else + { push (@Bad, $key) } + } + + if (@Bad) { + my ($bad) = join(", ", @Bad) ; + return $self->setError("unknown key value(s) @Bad") ; + } + + return 1; +} + +sub IO::Compress::Base::Parameters::_checkType +{ + my $self = shift ; + + my $key = shift ; + my $value = shift ; + my $type = shift ; + my $validate = shift ; + my $output = shift; + + #local $Carp::CarpLevel = $level ; + #print "PARSE $type $key $value $validate $sub\n" ; + + if ($type & Parse_writable_scalar) + { + return $self->setError("Parameter '$key' not writable") + if $validate && readonly $$value ; + + if (ref $$value) + { + return $self->setError("Parameter '$key' not a scalar reference") + if $validate && ref $$value ne 'SCALAR' ; + + $$output = $$value ; + } + else + { + return $self->setError("Parameter '$key' not a scalar") + if $validate && ref $value ne 'SCALAR' ; + + $$output = $value ; + } + + return 1; + } + +# if ($type & Parse_store_ref) +# { +# #$value = $$value +# # if ref ${ $value } ; +# +# $$output = $value ; +# return 1; +# } + + $value = $$value ; + + if ($type & Parse_any) + { + $$output = $value ; + return 1; + } + elsif ($type & Parse_unsigned) + { + return $self->setError("Parameter '$key' must be an unsigned int, got 'undef'") + if $validate && ! defined $value ; + return $self->setError("Parameter '$key' must be an unsigned int, got '$value'") + if $validate && $value !~ /^\d+$/; + + $$output = defined $value ? $value : 0 ; + return 1; + } + elsif ($type & Parse_signed) + { + return $self->setError("Parameter '$key' must be a signed int, got 'undef'") + if $validate && ! defined $value ; + return $self->setError("Parameter '$key' must be a signed int, got '$value'") + if $validate && $value !~ /^-?\d+$/; + + $$output = defined $value ? $value : 0 ; + return 1 ; + } + elsif ($type & Parse_boolean) + { + return $self->setError("Parameter '$key' must be an int, got '$value'") + if $validate && defined $value && $value !~ /^\d*$/; + $$output = defined $value ? $value != 0 : 0 ; + return 1; + } + elsif ($type & Parse_string) + { + $$output = defined $value ? $value : "" ; + return 1; + } + + $$output = $value ; + return 1; +} + + + +sub IO::Compress::Base::Parameters::parsed +{ + my $self = shift ; + my $name = shift ; + + return $self->{Got}{lc $name}[OFF_PARSED] ; +} + +sub IO::Compress::Base::Parameters::value +{ + my $self = shift ; + my $name = shift ; + + if (@_) + { + $self->{Got}{lc $name}[OFF_PARSED] = 1; + $self->{Got}{lc $name}[OFF_DEFAULT] = $_[0] ; + $self->{Got}{lc $name}[OFF_FIXED] = $_[0] ; + } + + return $self->{Got}{lc $name}[OFF_FIXED] ; +} + +sub IO::Compress::Base::Parameters::valueOrDefault +{ + my $self = shift ; + my $name = shift ; + my $default = shift ; + + my $value = $self->{Got}{lc $name}[OFF_DEFAULT] ; + + return $value if defined $value ; + return $default ; +} + +sub IO::Compress::Base::Parameters::wantValue +{ + my $self = shift ; + my $name = shift ; + + return defined $self->{Got}{lc $name}[OFF_DEFAULT] ; + +} + +sub IO::Compress::Base::Parameters::clone +{ + my $self = shift ; + my $obj = { }; + my %got ; + + while (my ($k, $v) = each %{ $self->{Got} }) { + $got{$k} = [ @$v ]; + } + + $obj->{Error} = $self->{Error}; + $obj->{Got} = \%got ; + + return bless $obj, 'IO::Compress::Base::Parameters' ; +} + +package U64; + +use constant MAX32 => 0xFFFFFFFF ; +use constant LOW => 0 ; +use constant HIGH => 1; + +sub new +{ + my $class = shift ; + + my $high = 0 ; + my $low = 0 ; + + if (@_ == 2) { + $high = shift ; + $low = shift ; + } + elsif (@_ == 1) { + $low = shift ; + } + + bless [$low, $high], $class; +} + +sub newUnpack_V64 +{ + my $string = shift; + + my ($low, $hi) = unpack "V V", $string ; + bless [ $low, $hi ], "U64"; +} + +sub newUnpack_V32 +{ + my $string = shift; + + my $low = unpack "V", $string ; + bless [ $low, 0 ], "U64"; +} + +sub reset +{ + my $self = shift; + $self->[HIGH] = $self->[LOW] = 0; +} + +sub clone +{ + my $self = shift; + bless [ @$self ], ref $self ; +} + +sub getHigh +{ + my $self = shift; + return $self->[HIGH]; +} + +sub getLow +{ + my $self = shift; + return $self->[LOW]; +} + +sub get32bit +{ + my $self = shift; + return $self->[LOW]; +} + +sub add +{ + my $self = shift; + my $value = shift; + + if (ref $value eq 'U64') { + $self->[HIGH] += $value->[HIGH] ; + $value = $value->[LOW]; + } + + my $available = MAX32 - $self->[LOW] ; + + if ($value > $available) { + ++ $self->[HIGH] ; + $self->[LOW] = $value - $available - 1; + } + else { + $self->[LOW] += $value ; + } +} + +sub equal +{ + my $self = shift; + my $other = shift; + + return $self->[LOW] == $other->[LOW] && + $self->[HIGH] == $other->[HIGH] ; +} + +sub getPacked_V64 +{ + my $self = shift; + + return pack "V V", @$self ; +} + +sub getPacked_V32 +{ + my $self = shift; + + return pack "V", $self->[LOW] ; +} + +sub pack_V64 +{ + my $low = shift; + + return pack "V V", $low, 0; +} + + +package IO::Compress::Base::Common; + +1; diff --git a/ext/IO-Compress/lib/IO/Compress/Bzip2.pm b/ext/IO-Compress/lib/IO/Compress/Bzip2.pm new file mode 100644 index 0000000000..356ba1a2c4 --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Bzip2.pm @@ -0,0 +1,758 @@ +package IO::Compress::Bzip2 ; + +use strict ; +use warnings; +use bytes; +require Exporter ; + +use IO::Compress::Base 2.016 ; + +use IO::Compress::Base::Common 2.016 qw(createSelfTiedObject); +use IO::Compress::Adapter::Bzip2 2.016 ; + + + +our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $Bzip2Error); + +$VERSION = '2.016'; +$Bzip2Error = ''; + +@ISA = qw(Exporter IO::Compress::Base); +@EXPORT_OK = qw( $Bzip2Error bzip2 ) ; +%EXPORT_TAGS = %IO::Compress::Base::EXPORT_TAGS ; +push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; +Exporter::export_ok_tags('all'); + + + +sub new +{ + my $class = shift ; + + my $obj = createSelfTiedObject($class, \$Bzip2Error); + return $obj->_create(undef, @_); +} + +sub bzip2 +{ + my $obj = createSelfTiedObject(undef, \$Bzip2Error); + $obj->_def(@_); +} + + +sub mkHeader +{ + my $self = shift ; + return ''; + +} + +sub getExtraParams +{ + my $self = shift ; + + use IO::Compress::Base::Common 2.016 qw(:Parse); + + return ( + 'BlockSize100K' => [0, 1, Parse_unsigned, 1], + 'WorkFactor' => [0, 1, Parse_unsigned, 0], + 'Verbosity' => [0, 1, Parse_boolean, 0], + ); +} + + + +sub ckParams +{ + my $self = shift ; + my $got = shift; + + # check that BlockSize100K is a number between 1 & 9 + if ($got->parsed('BlockSize100K')) { + my $value = $got->value('BlockSize100K'); + return $self->saveErrorString(undef, "Parameter 'BlockSize100K' not between 1 and 9, got $value") + unless defined $value && $value >= 1 && $value <= 9; + + } + + # check that WorkFactor between 0 & 250 + if ($got->parsed('WorkFactor')) { + my $value = $got->value('WorkFactor'); + return $self->saveErrorString(undef, "Parameter 'WorkFactor' not between 0 and 250, got $value") + unless $value >= 0 && $value <= 250; + } + + return 1 ; +} + + +sub mkComp +{ + my $self = shift ; + my $got = shift ; + + my $BlockSize100K = $got->value('BlockSize100K'); + my $WorkFactor = $got->value('WorkFactor'); + my $Verbosity = $got->value('Verbosity'); + + my ($obj, $errstr, $errno) = IO::Compress::Adapter::Bzip2::mkCompObject( + $BlockSize100K, $WorkFactor, + $Verbosity); + + return $self->saveErrorString(undef, $errstr, $errno) + if ! defined $obj; + + return $obj; +} + + +sub mkTrailer +{ + my $self = shift ; + return ''; +} + +sub mkFinalTrailer +{ + return ''; +} + +#sub newHeader +#{ +# my $self = shift ; +# return ''; +#} + +sub getInverseClass +{ + return ('IO::Uncompress::Bunzip2'); +} + +sub getFileInfo +{ + my $self = shift ; + my $params = shift; + my $file = shift ; + +} + +1; + +__END__ + +=head1 NAME + +IO::Compress::Bzip2 - Write bzip2 files/buffers + + + +=head1 SYNOPSIS + + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + my $status = bzip2 $input => $output [,OPTS] + or die "bzip2 failed: $Bzip2Error\n"; + + my $z = new IO::Compress::Bzip2 $output [,OPTS] + or die "bzip2 failed: $Bzip2Error\n"; + + $z->print($string); + $z->printf($format, $string); + $z->write($string); + $z->syswrite($string [, $length, $offset]); + $z->flush(); + $z->tell(); + $z->eof(); + $z->seek($position, $whence); + $z->binmode(); + $z->fileno(); + $z->opened(); + $z->autoflush(); + $z->input_line_number(); + $z->newStream( [OPTS] ); + + $z->close() ; + + $Bzip2Error ; + + # IO::File mode + + print $z $string; + printf $z $format, $string; + tell $z + eof $z + seek $z, $position, $whence + binmode $z + fileno $z + close $z ; + + +=head1 DESCRIPTION + +This module provides a Perl interface that allows writing bzip2 +compressed data to files or buffer. + +For reading bzip2 files/buffers, see the companion module +L. + +=head1 Functional Interface + +A top-level function, C, is provided to carry out +"one-shot" compression between buffers and/or files. For finer +control over the compression process, see the L +section. + + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + bzip2 $input => $output [,OPTS] + or die "bzip2 failed: $Bzip2Error\n"; + +The functional interface needs Perl5.005 or better. + +=head2 bzip2 $input => $output [, OPTS] + +C expects at least two parameters, C<$input> and C<$output>. + +=head3 The C<$input> parameter + +The parameter, C<$input>, is used to define the source of +the uncompressed data. + +It can take one of the following forms: + +=over 5 + +=item A filename + +If the C<$input> parameter is a simple scalar, it is assumed to be a +filename. This file will be opened for reading and the input data +will be read from it. + +=item A filehandle + +If the C<$input> parameter is a filehandle, the input data will be +read from it. +The string '-' can be used as an alias for standard input. + +=item A scalar reference + +If C<$input> is a scalar reference, the input data will be read +from C<$$input>. + +=item An array reference + +If C<$input> is an array reference, each element in the array must be a +filename. + +The input data will be read from each file in turn. + +The complete array will be walked to ensure that it only +contains valid filenames before any data is compressed. + +=item An Input FileGlob string + +If C<$input> is a string that is delimited by the characters "<" and ">" +C will assume that it is an I. The +input is the list of files that match the fileglob. + +If the fileglob does not match any files ... + +See L for more details. + +=back + +If the C<$input> parameter is any other type, C will be returned. + +=head3 The C<$output> parameter + +The parameter C<$output> is used to control the destination of the +compressed data. This parameter can take one of these forms. + +=over 5 + +=item A filename + +If the C<$output> parameter is a simple scalar, it is assumed to be a +filename. This file will be opened for writing and the compressed +data will be written to it. + +=item A filehandle + +If the C<$output> parameter is a filehandle, the compressed data +will be written to it. +The string '-' can be used as an alias for standard output. + +=item A scalar reference + +If C<$output> is a scalar reference, the compressed data will be +stored in C<$$output>. + +=item An Array Reference + +If C<$output> is an array reference, the compressed data will be +pushed onto the array. + +=item An Output FileGlob + +If C<$output> is a string that is delimited by the characters "<" and ">" +C will assume that it is an I. The +output is the list of files that match the fileglob. + +When C<$output> is an fileglob string, C<$input> must also be a fileglob +string. Anything else is an error. + +=back + +If the C<$output> parameter is any other type, C will be returned. + +=head2 Notes + +When C<$input> maps to multiple files/buffers and C<$output> is a single +file/buffer the input files/buffers will be stored +in C<$output> as a concatenated series of compressed data streams. + +=head2 Optional Parameters + +Unless specified below, the optional parameters for C, +C, are the same as those used with the OO interface defined in the +L section below. + +=over 5 + +=item C<< AutoClose => 0|1 >> + +This option applies to any input or output data streams to +C that are filehandles. + +If C is specified, and the value is true, it will result in all +input and/or output filehandles being closed once C has +completed. + +This parameter defaults to 0. + +=item C<< BinModeIn => 0|1 >> + +When reading from a file or filehandle, set C before reading. + +Defaults to 0. + +=item C<< Append => 0|1 >> + +TODO + +=back + +=head2 Examples + +To read the contents of the file C and write the compressed +data to the file C. + + use strict ; + use warnings ; + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + my $input = "file1.txt"; + bzip2 $input => "$input.bz2" + or die "bzip2 failed: $Bzip2Error\n"; + +To read from an existing Perl filehandle, C<$input>, and write the +compressed data to a buffer, C<$buffer>. + + use strict ; + use warnings ; + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + use IO::File ; + + my $input = new IO::File " \$buffer + or die "bzip2 failed: $Bzip2Error\n"; + +To compress all files in the directory "/my/home" that match "*.txt" +and store the compressed data in the same directory + + use strict ; + use warnings ; + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + bzip2 '' => '<*.bz2>' + or die "bzip2 failed: $Bzip2Error\n"; + +and if you want to compress each file one at a time, this will do the trick + + use strict ; + use warnings ; + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + for my $input ( glob "/my/home/*.txt" ) + { + my $output = "$input.bz2" ; + bzip2 $input => $output + or die "Error compressing '$input': $Bzip2Error\n"; + } + +=head1 OO Interface + +=head2 Constructor + +The format of the constructor for C is shown below + + my $z = new IO::Compress::Bzip2 $output [,OPTS] + or die "IO::Compress::Bzip2 failed: $Bzip2Error\n"; + +It returns an C object on success and undef on failure. +The variable C<$Bzip2Error> will contain an error message on failure. + +If you are running Perl 5.005 or better the object, C<$z>, returned from +IO::Compress::Bzip2 can be used exactly like an L filehandle. +This means that all normal output file operations can be carried out +with C<$z>. +For example, to write to a compressed file/buffer you can use either of +these forms + + $z->print("hello world\n"); + print $z "hello world\n"; + +The mandatory parameter C<$output> is used to control the destination +of the compressed data. This parameter can take one of these forms. + +=over 5 + +=item A filename + +If the C<$output> parameter is a simple scalar, it is assumed to be a +filename. This file will be opened for writing and the compressed data +will be written to it. + +=item A filehandle + +If the C<$output> parameter is a filehandle, the compressed data will be +written to it. +The string '-' can be used as an alias for standard output. + +=item A scalar reference + +If C<$output> is a scalar reference, the compressed data will be stored +in C<$$output>. + +=back + +If the C<$output> parameter is any other type, C::new will +return undef. + +=head2 Constructor Options + +C is any combination of the following options: + +=over 5 + +=item C<< AutoClose => 0|1 >> + +This option is only valid when the C<$output> parameter is a filehandle. If +specified, and the value is true, it will result in the C<$output> being +closed once either the C method is called or the C +object is destroyed. + +This parameter defaults to 0. + +=item C<< Append => 0|1 >> + +Opens C<$output> in append mode. + +The behaviour of this option is dependent on the type of C<$output>. + +=over 5 + +=item * A Buffer + +If C<$output> is a buffer and C is enabled, all compressed data +will be append to the end if C<$output>. Otherwise C<$output> will be +cleared before any data is written to it. + +=item * A Filename + +If C<$output> is a filename and C is enabled, the file will be +opened in append mode. Otherwise the contents of the file, if any, will be +truncated before any compressed data is written to it. + +=item * A Filehandle + +If C<$output> is a filehandle, the file pointer will be positioned to the +end of the file via a call to C before any compressed data is written +to it. Otherwise the file pointer will not be moved. + +=back + +This parameter defaults to 0. + +=item C<< BlockSize100K => number >> + +Specify the number of 100K blocks bzip2 uses during compression. + +Valid values are from 1 to 9, where 9 is best compression. + +The default is 1. + +=item C<< WorkFactor => number >> + +Specifies how much effort bzip2 should take before resorting to a slower +fallback compression algorithm. + +Valid values range from 0 to 250, where 0 means use the default value 30. + +The default is 0. + +=item C<< Strict => 0|1 >> + +This is a placeholder option. + +=back + +=head2 Examples + +TODO + +=head1 Methods + +=head2 print + +Usage is + + $z->print($data) + print $z $data + +Compresses and outputs the contents of the C<$data> parameter. This +has the same behaviour as the C built-in. + +Returns true if successful. + +=head2 printf + +Usage is + + $z->printf($format, $data) + printf $z $format, $data + +Compresses and outputs the contents of the C<$data> parameter. + +Returns true if successful. + +=head2 syswrite + +Usage is + + $z->syswrite $data + $z->syswrite $data, $length + $z->syswrite $data, $length, $offset + +Compresses and outputs the contents of the C<$data> parameter. + +Returns the number of uncompressed bytes written, or C if +unsuccessful. + +=head2 write + +Usage is + + $z->write $data + $z->write $data, $length + $z->write $data, $length, $offset + +Compresses and outputs the contents of the C<$data> parameter. + +Returns the number of uncompressed bytes written, or C if +unsuccessful. + +=head2 flush + +Usage is + + $z->flush; + +Flushes any pending compressed data to the output file/buffer. + +TODO + +Returns true on success. + +=head2 tell + +Usage is + + $z->tell() + tell $z + +Returns the uncompressed file offset. + +=head2 eof + +Usage is + + $z->eof(); + eof($z); + +Returns true if the C method has been called. + +=head2 seek + + $z->seek($position, $whence); + seek($z, $position, $whence); + +Provides a sub-set of the C functionality, with the restriction +that it is only legal to seek forward in the output file/buffer. +It is a fatal error to attempt to seek backward. + +Empty parts of the file/buffer will have NULL (0x00) bytes written to them. + +The C<$whence> parameter takes one the usual values, namely SEEK_SET, +SEEK_CUR or SEEK_END. + +Returns 1 on success, 0 on failure. + +=head2 binmode + +Usage is + + $z->binmode + binmode $z ; + +This is a noop provided for completeness. + +=head2 opened + + $z->opened() + +Returns true if the object currently refers to a opened file/buffer. + +=head2 autoflush + + my $prev = $z->autoflush() + my $prev = $z->autoflush(EXPR) + +If the C<$z> object is associated with a file or a filehandle, this method +returns the current autoflush setting for the underlying filehandle. If +C is present, and is non-zero, it will enable flushing after every +write/print operation. + +If C<$z> is associated with a buffer, this method has no effect and always +returns C. + +B that the special variable C<$|> B be used to set or +retrieve the autoflush setting. + +=head2 input_line_number + + $z->input_line_number() + $z->input_line_number(EXPR) + +This method always returns C when compressing. + +=head2 fileno + + $z->fileno() + fileno($z) + +If the C<$z> object is associated with a file or a filehandle, C +will return the underlying file descriptor. Once the C method is +called C will return C. + +If the C<$z> object is is associated with a buffer, this method will return +C. + +=head2 close + + $z->close() ; + close $z ; + +Flushes any pending compressed data and then closes the output file/buffer. + +For most versions of Perl this method will be automatically invoked if +the IO::Compress::Bzip2 object is destroyed (either explicitly or by the +variable with the reference to the object going out of scope). The +exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In +these cases, the C method will be called automatically, but +not until global destruction of all live objects when the program is +terminating. + +Therefore, if you want your scripts to be able to run on all versions +of Perl, you should call C explicitly and not rely on automatic +closing. + +Returns true on success, otherwise 0. + +If the C option has been enabled when the IO::Compress::Bzip2 +object was created, and the object is associated with a file, the +underlying file will also be closed. + +=head2 newStream([OPTS]) + +Usage is + + $z->newStream( [OPTS] ) + +Closes the current compressed data stream and starts a new one. + +OPTS consists of any of the the options that are available when creating +the C<$z> object. + +See the L section for more details. + +=head1 Importing + +No symbolic constants are required by this IO::Compress::Bzip2 at present. + +=over 5 + +=item :all + +Imports C and C<$Bzip2Error>. +Same as doing this + + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + + +=back + +=head1 EXAMPLES + +=head2 Apache::GZip Revisited + +See L + + + +=head2 Working with Net::FTP + +See L + +=head1 SEE ALSO + +L, L, L, L, L, L, L, L, L, L, L, L, L, L + +L + +L, L, +L, +L + +The primary site for the bzip2 program is F. + +See the module L + +=head1 AUTHOR + +This module was written by Paul Marquess, F. + +=head1 MODIFICATION HISTORY + +See the Changes file. + +=head1 COPYRIGHT AND LICENSE + +Copyright (c) 2005-2008 Paul Marquess. All rights reserved. + +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + diff --git a/ext/IO-Compress/lib/IO/Compress/Deflate.pm b/ext/IO-Compress/lib/IO/Compress/Deflate.pm new file mode 100644 index 0000000000..05466f3a66 --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Deflate.pm @@ -0,0 +1,889 @@ +package IO::Compress::Deflate ; + +use strict ; +use warnings; +use bytes; + +require Exporter ; + +use IO::Compress::RawDeflate 2.017 ; + +use Compress::Raw::Zlib 2.017 ; +use IO::Compress::Zlib::Constants 2.017 ; +use IO::Compress::Base::Common 2.017 qw(createSelfTiedObject); + + +our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $DeflateError); + +$VERSION = '2.017'; +$DeflateError = ''; + +@ISA = qw(Exporter IO::Compress::RawDeflate); +@EXPORT_OK = qw( $DeflateError deflate ) ; +%EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ; +push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; +Exporter::export_ok_tags('all'); + + +sub new +{ + my $class = shift ; + + my $obj = createSelfTiedObject($class, \$DeflateError); + return $obj->_create(undef, @_); +} + +sub deflate +{ + my $obj = createSelfTiedObject(undef, \$DeflateError); + return $obj->_def(@_); +} + + +sub bitmask($$$$) +{ + my $into = shift ; + my $value = shift ; + my $offset = shift ; + my $mask = shift ; + + return $into | (($value & $mask) << $offset ) ; +} + +sub mkDeflateHdr($$$;$) +{ + my $method = shift ; + my $cinfo = shift; + my $level = shift; + my $fdict_adler = shift ; + + my $cmf = 0; + my $flg = 0; + my $fdict = 0; + $fdict = 1 if defined $fdict_adler; + + $cmf = bitmask($cmf, $method, ZLIB_CMF_CM_OFFSET, ZLIB_CMF_CM_BITS); + $cmf = bitmask($cmf, $cinfo, ZLIB_CMF_CINFO_OFFSET, ZLIB_CMF_CINFO_BITS); + + $flg = bitmask($flg, $fdict, ZLIB_FLG_FDICT_OFFSET, ZLIB_FLG_FDICT_BITS); + $flg = bitmask($flg, $level, ZLIB_FLG_LEVEL_OFFSET, ZLIB_FLG_LEVEL_BITS); + + my $fcheck = 31 - ($cmf * 256 + $flg) % 31 ; + $flg = bitmask($flg, $fcheck, ZLIB_FLG_FCHECK_OFFSET, ZLIB_FLG_FCHECK_BITS); + + my $hdr = pack("CC", $cmf, $flg) ; + $hdr .= pack("N", $fdict_adler) if $fdict ; + + return $hdr; +} + +sub mkHeader +{ + my $self = shift ; + my $param = shift ; + + my $level = $param->value('Level'); + my $strategy = $param->value('Strategy'); + + my $lflag ; + $level = 6 + if $level == Z_DEFAULT_COMPRESSION ; + + if (ZLIB_VERNUM >= 0x1210) + { + if ($strategy >= Z_HUFFMAN_ONLY || $level < 2) + { $lflag = ZLIB_FLG_LEVEL_FASTEST } + elsif ($level < 6) + { $lflag = ZLIB_FLG_LEVEL_FAST } + elsif ($level == 6) + { $lflag = ZLIB_FLG_LEVEL_DEFAULT } + else + { $lflag = ZLIB_FLG_LEVEL_SLOWEST } + } + else + { + $lflag = ($level - 1) >> 1 ; + $lflag = 3 if $lflag > 3 ; + } + + #my $wbits = (MAX_WBITS - 8) << 4 ; + my $wbits = 7; + mkDeflateHdr(ZLIB_CMF_CM_DEFLATED, $wbits, $lflag); +} + +sub ckParams +{ + my $self = shift ; + my $got = shift; + + $got->value('ADLER32' => 1); + return 1 ; +} + + +sub mkTrailer +{ + my $self = shift ; + return pack("N", *$self->{Compress}->adler32()) ; +} + +sub mkFinalTrailer +{ + return ''; +} + +#sub newHeader +#{ +# my $self = shift ; +# return *$self->{Header}; +#} + +sub getExtraParams +{ + my $self = shift ; + return $self->getZlibParams(), +} + +sub getInverseClass +{ + return ('IO::Uncompress::Inflate', + \$IO::Uncompress::Inflate::InflateError); +} + +sub getFileInfo +{ + my $self = shift ; + my $params = shift; + my $file = shift ; + +} + + + +1; + +__END__ + +=head1 NAME + +IO::Compress::Deflate - Write RFC 1950 files/buffers + + + +=head1 SYNOPSIS + + use IO::Compress::Deflate qw(deflate $DeflateError) ; + + my $status = deflate $input => $output [,OPTS] + or die "deflate failed: $DeflateError\n"; + + my $z = new IO::Compress::Deflate $output [,OPTS] + or die "deflate failed: $DeflateError\n"; + + $z->print($string); + $z->printf($format, $string); + $z->write($string); + $z->syswrite($string [, $length, $offset]); + $z->flush(); + $z->tell(); + $z->eof(); + $z->seek($position, $whence); + $z->binmode(); + $z->fileno(); + $z->opened(); + $z->autoflush(); + $z->input_line_number(); + $z->newStream( [OPTS] ); + + $z->deflateParams(); + + $z->close() ; + + $DeflateError ; + + # IO::File mode + + print $z $string; + printf $z $format, $string; + tell $z + eof $z + seek $z, $position, $whence + binmode $z + fileno $z + close $z ; + + +=head1 DESCRIPTION + +This module provides a Perl interface that allows writing compressed +data to files or buffer as defined in RFC 1950. + +For reading RFC 1950 files/buffers, see the companion module +L. + +=head1 Functional Interface + +A top-level function, C, is provided to carry out +"one-shot" compression between buffers and/or files. For finer +control over the compression process, see the L +section. + + use IO::Compress::Deflate qw(deflate $DeflateError) ; + + deflate $input => $output [,OPTS] + or die "deflate failed: $DeflateError\n"; + +The functional interface needs Perl5.005 or better. + +=head2 deflate $input => $output [, OPTS] + +C expects at least two parameters, C<$input> and C<$output>. + +=head3 The C<$input> parameter + +The parameter, C<$input>, is used to define the source of +the uncompressed data. + +It can take one of the following forms: + +=over 5 + +=item A filename + +If the C<$input> parameter is a simple scalar, it is assumed to be a +filename. This file will be opened for reading and the input data +will be read from it. + +=item A filehandle + +If the C<$input> parameter is a filehandle, the input data will be +read from it. +The string '-' can be used as an alias for standard input. + +=item A scalar reference + +If C<$input> is a scalar reference, the input data will be read +from C<$$input>. + +=item An array reference + +If C<$input> is an array reference, each element in the array must be a +filename. + +The input data will be read from each file in turn. + +The complete array will be walked to ensure that it only +contains valid filenames before any data is compressed. + +=item An Input FileGlob string + +If C<$input> is a string that is delimited by the characters "<" and ">" +C will assume that it is an I. The +input is the list of files that match the fileglob. + +If the fileglob does not match any files ... + +See L for more details. + +=back + +If the C<$input> parameter is any other type, C will be returned. + +=head3 The C<$output> parameter + +The parameter C<$output> is used to control the destination of the +compressed data. This parameter can take one of these forms. + +=over 5 + +=item A filename + +If the C<$output> parameter is a simple scalar, it is assumed to be a +filename. This file will be opened for writing and the compressed +data will be written to it. + +=item A filehandle + +If the C<$output> parameter is a filehandle, the compressed data +will be written to it. +The string '-' can be used as an alias for standard output. + +=item A scalar reference + +If C<$output> is a scalar reference, the compressed data will be +stored in C<$$output>. + +=item An Array Reference + +If C<$output> is an array reference, the compressed data will be +pushed onto the array. + +=item An Output FileGlob + +If C<$output> is a string that is delimited by the characters "<" and ">" +C will assume that it is an I. The +output is the list of files that match the fileglob. + +When C<$output> is an fileglob string, C<$input> must also be a fileglob +string. Anything else is an error. + +=back + +If the C<$output> parameter is any other type, C will be returned. + +=head2 Notes + +When C<$input> maps to multiple files/buffers and C<$output> is a single +file/buffer the input files/buffers will be stored +in C<$output> as a concatenated series of compressed data streams. + +=head2 Optional Parameters + +Unless specified below, the optional parameters for C, +C, are the same as those used with the OO interface defined in the +L section below. + +=over 5 + +=item C<< AutoClose => 0|1 >> + +This option applies to any input or output data streams to +C that are filehandles. + +If C is specified, and the value is true, it will result in all +input and/or output filehandles being closed once C has +completed. + +This parameter defaults to 0. + +=item C<< BinModeIn => 0|1 >> + +When reading from a file or filehandle, set C before reading. + +Defaults to 0. + +=item C<< Append => 0|1 >> + +TODO + +=back + +=head2 Examples + +To read the contents of the file C and write the compressed +data to the file C. + + use strict ; + use warnings ; + use IO::Compress::Deflate qw(deflate $DeflateError) ; + + my $input = "file1.txt"; + deflate $input => "$input.1950" + or die "deflate failed: $DeflateError\n"; + +To read from an existing Perl filehandle, C<$input>, and write the +compressed data to a buffer, C<$buffer>. + + use strict ; + use warnings ; + use IO::Compress::Deflate qw(deflate $DeflateError) ; + use IO::File ; + + my $input = new IO::File " \$buffer + or die "deflate failed: $DeflateError\n"; + +To compress all files in the directory "/my/home" that match "*.txt" +and store the compressed data in the same directory + + use strict ; + use warnings ; + use IO::Compress::Deflate qw(deflate $DeflateError) ; + + deflate '' => '<*.1950>' + or die "deflate failed: $DeflateError\n"; + +and if you want to compress each file one at a time, this will do the trick + + use strict ; + use warnings ; + use IO::Compress::Deflate qw(deflate $DeflateError) ; + + for my $input ( glob "/my/home/*.txt" ) + { + my $output = "$input.1950" ; + deflate $input => $output + or die "Error compressing '$input': $DeflateError\n"; + } + +=head1 OO Interface + +=head2 Constructor + +The format of the constructor for C is shown below + + my $z = new IO::Compress::Deflate $output [,OPTS] + or die "IO::Compress::Deflate failed: $DeflateError\n"; + +It returns an C object on success and undef on failure. +The variable C<$DeflateError> will contain an error message on failure. + +If you are running Perl 5.005 or better the object, C<$z>, returned from +IO::Compress::Deflate can be used exactly like an L filehandle. +This means that all normal output file operations can be carried out +with C<$z>. +For example, to write to a compressed file/buffer you can use either of +these forms + + $z->print("hello world\n"); + print $z "hello world\n"; + +The mandatory parameter C<$output> is used to control the destination +of the compressed data. This parameter can take one of these forms. + +=over 5 + +=item A filename + +If the C<$output> parameter is a simple scalar, it is assumed to be a +filename. This file will be opened for writing and the compressed data +will be written to it. + +=item A filehandle + +If the C<$output> parameter is a filehandle, the compressed data will be +written to it. +The string '-' can be used as an alias for standard output. + +=item A scalar reference + +If C<$output> is a scalar reference, the compressed data will be stored +in C<$$output>. + +=back + +If the C<$output> parameter is any other type, C::new will +return undef. + +=head2 Constructor Options + +C is any combination of the following options: + +=over 5 + +=item C<< AutoClose => 0|1 >> + +This option is only valid when the C<$output> parameter is a filehandle. If +specified, and the value is true, it will result in the C<$output> being +closed once either the C method is called or the C +object is destroyed. + +This parameter defaults to 0. + +=item C<< Append => 0|1 >> + +Opens C<$output> in append mode. + +The behaviour of this option is dependent on the type of C<$output>. + +=over 5 + +=item * A Buffer + +If C<$output> is a buffer and C is enabled, all compressed data +will be append to the end if C<$output>. Otherwise C<$output> will be +cleared before any data is written to it. + +=item * A Filename + +If C<$output> is a filename and C is enabled, the file will be +opened in append mode. Otherwise the contents of the file, if any, will be +truncated before any compressed data is written to it. + +=item * A Filehandle + +If C<$output> is a filehandle, the file pointer will be positioned to the +end of the file via a call to C before any compressed data is written +to it. Otherwise the file pointer will not be moved. + +=back + +This parameter defaults to 0. + +=item C<< Merge => 0|1 >> + +This option is used to compress input data and append it to an existing +compressed data stream in C<$output>. The end result is a single compressed +data stream stored in C<$output>. + +It is a fatal error to attempt to use this option when C<$output> is not an +RFC 1950 data stream. + +There are a number of other limitations with the C option: + +=over 5 + +=item 1 + +This module needs to have been built with zlib 1.2.1 or better to work. A +fatal error will be thrown if C is used with an older version of +zlib. + +=item 2 + +If C<$output> is a file or a filehandle, it must be seekable. + +=back + +This parameter defaults to 0. + +=item -Level + +Defines the compression level used by zlib. The value should either be +a number between 0 and 9 (0 means no compression and 9 is maximum +compression), or one of the symbolic constants defined below. + + Z_NO_COMPRESSION + Z_BEST_SPEED + Z_BEST_COMPRESSION + Z_DEFAULT_COMPRESSION + +The default is Z_DEFAULT_COMPRESSION. + +Note, these constants are not imported by C by default. + + use IO::Compress::Deflate qw(:strategy); + use IO::Compress::Deflate qw(:constants); + use IO::Compress::Deflate qw(:all); + +=item -Strategy + +Defines the strategy used to tune the compression. Use one of the symbolic +constants defined below. + + Z_FILTERED + Z_HUFFMAN_ONLY + Z_RLE + Z_FIXED + Z_DEFAULT_STRATEGY + +The default is Z_DEFAULT_STRATEGY. + +=item C<< Strict => 0|1 >> + +This is a placeholder option. + +=back + +=head2 Examples + +TODO + +=head1 Methods + +=head2 print + +Usage is + + $z->print($data) + print $z $data + +Compresses and outputs the contents of the C<$data> parameter. This +has the same behaviour as the C built-in. + +Returns true if successful. + +=head2 printf + +Usage is + + $z->printf($format, $data) + printf $z $format, $data + +Compresses and outputs the contents of the C<$data> parameter. + +Returns true if successful. + +=head2 syswrite + +Usage is + + $z->syswrite $data + $z->syswrite $data, $length + $z->syswrite $data, $length, $offset + +Compresses and outputs the contents of the C<$data> parameter. + +Returns the number of uncompressed bytes written, or C if +unsuccessful. + +=head2 write + +Usage is + + $z->write $data + $z->write $data, $length + $z->write $data, $length, $offset + +Compresses and outputs the contents of the C<$data> parameter. + +Returns the number of uncompressed bytes written, or C if +unsuccessful. + +=head2 flush + +Usage is + + $z->flush; + $z->flush($flush_type); + +Flushes any pending compressed data to the output file/buffer. + +This method takes an optional parameter, C<$flush_type>, that controls +how the flushing will be carried out. By default the C<$flush_type> +used is C. Other valid values for C<$flush_type> are +C, C, C and C. It is +strongly recommended that you only set the C parameter if +you fully understand the implications of what it does - overuse of C +can seriously degrade the level of compression achieved. See the C +documentation for details. + +Returns true on success. + +=head2 tell + +Usage is + + $z->tell() + tell $z + +Returns the uncompressed file offset. + +=head2 eof + +Usage is + + $z->eof(); + eof($z); + +Returns true if the C method has been called. + +=head2 seek + + $z->seek($position, $whence); + seek($z, $position, $whence); + +Provides a sub-set of the C functionality, with the restriction +that it is only legal to seek forward in the output file/buffer. +It is a fatal error to attempt to seek backward. + +Empty parts of the file/buffer will have NULL (0x00) bytes written to them. + +The C<$whence> parameter takes one the usual values, namely SEEK_SET, +SEEK_CUR or SEEK_END. + +Returns 1 on success, 0 on failure. + +=head2 binmode + +Usage is + + $z->binmode + binmode $z ; + +This is a noop provided for completeness. + +=head2 opened + + $z->opened() + +Returns true if the object currently refers to a opened file/buffer. + +=head2 autoflush + + my $prev = $z->autoflush() + my $prev = $z->autoflush(EXPR) + +If the C<$z> object is associated with a file or a filehandle, this method +returns the current autoflush setting for the underlying filehandle. If +C is present, and is non-zero, it will enable flushing after every +write/print operation. + +If C<$z> is associated with a buffer, this method has no effect and always +returns C. + +B that the special variable C<$|> B be used to set or +retrieve the autoflush setting. + +=head2 input_line_number + + $z->input_line_number() + $z->input_line_number(EXPR) + +This method always returns C when compressing. + +=head2 fileno + + $z->fileno() + fileno($z) + +If the C<$z> object is associated with a file or a filehandle, C +will return the underlying file descriptor. Once the C method is +called C will return C. + +If the C<$z> object is is associated with a buffer, this method will return +C. + +=head2 close + + $z->close() ; + close $z ; + +Flushes any pending compressed data and then closes the output file/buffer. + +For most versions of Perl this method will be automatically invoked if +the IO::Compress::Deflate object is destroyed (either explicitly or by the +variable with the reference to the object going out of scope). The +exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In +these cases, the C method will be called automatically, but +not until global destruction of all live objects when the program is +terminating. + +Therefore, if you want your scripts to be able to run on all versions +of Perl, you should call C explicitly and not rely on automatic +closing. + +Returns true on success, otherwise 0. + +If the C option has been enabled when the IO::Compress::Deflate +object was created, and the object is associated with a file, the +underlying file will also be closed. + +=head2 newStream([OPTS]) + +Usage is + + $z->newStream( [OPTS] ) + +Closes the current compressed data stream and starts a new one. + +OPTS consists of any of the the options that are available when creating +the C<$z> object. + +See the L section for more details. + +=head2 deflateParams + +Usage is + + $z->deflateParams + +TODO + +=head1 Importing + +A number of symbolic constants are required by some methods in +C. None are imported by default. + +=over 5 + +=item :all + +Imports C, C<$DeflateError> and all symbolic +constants that can be used by C. Same as doing this + + use IO::Compress::Deflate qw(deflate $DeflateError :constants) ; + +=item :constants + +Import all symbolic constants. Same as doing this + + use IO::Compress::Deflate qw(:flush :level :strategy) ; + +=item :flush + +These symbolic constants are used by the C method. + + Z_NO_FLUSH + Z_PARTIAL_FLUSH + Z_SYNC_FLUSH + Z_FULL_FLUSH + Z_FINISH + Z_BLOCK + +=item :level + +These symbolic constants are used by the C option in the constructor. + + Z_NO_COMPRESSION + Z_BEST_SPEED + Z_BEST_COMPRESSION + Z_DEFAULT_COMPRESSION + +=item :strategy + +These symbolic constants are used by the C option in the constructor. + + Z_FILTERED + Z_HUFFMAN_ONLY + Z_RLE + Z_FIXED + Z_DEFAULT_STRATEGY + + + + +=back + +=head1 EXAMPLES + +=head2 Apache::GZip Revisited + +See L + + + +=head2 Working with Net::FTP + +See L + +=head1 SEE ALSO + +L, L, L, L, L, L, L, L, L, L, L, L, L, L + +L + +L, L, +L, +L + +For RFC 1950, 1951 and 1952 see +F, +F and +F + +The I compression library was written by Jean-loup Gailly +F and Mark Adler F. + +The primary site for the I compression library is +F. + +The primary site for gzip is F. + +=head1 AUTHOR + +This module was written by Paul Marquess, F. + +=head1 MODIFICATION HISTORY + +See the Changes file. + +=head1 COPYRIGHT AND LICENSE + +Copyright (c) 2005-2009 Paul Marquess. All rights reserved. + +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + diff --git a/ext/IO-Compress/lib/IO/Compress/Gzip.pm b/ext/IO-Compress/lib/IO/Compress/Gzip.pm new file mode 100644 index 0000000000..cbdc985b1e --- /dev/null +++ b/ext/IO-Compress/lib/IO/Compress/Gzip.pm @@ -0,0 +1,1201 @@ + +package IO::Compress::Gzip ; + +require 5.004 ; + +use strict ; +use warnings; +use bytes; + + +use IO::Compress::RawDeflate 2.017 ; + +use Compress::Raw::Zlib 2.017 ; +use IO::Compress::Base::Common 2.017 qw(:Status :Parse createSelfTiedObject); +use IO::Compress::Gzip::Constants 2.017 ; +use IO::Compress::Zlib::Extra 2.017 ; + +BEGIN +{ + if (defined &utf8::downgrade ) + { *noUTF8 = \&utf8::downgrade } + else + { *noUTF8 = sub {} } +} + +require Exporter ; + +our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $GzipError); + +$VERSION = '2.017'; +$GzipError = '' ; + +@ISA = qw(Exporter IO::Compress::RawDeflate); +@EXPORT_OK = qw( $GzipError gzip ) ; +%EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ; +push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; +Exporter::export_ok_tags('all'); + +sub new +{ + my $class = shift ; + + my $obj = createSelfTiedObject($class, \$GzipError); + + $obj->_create(undef, @_); +} + + +sub gzip +{ + my $obj = createSelfTiedObject(undef, \$GzipError); + return $obj->_def(@_); +} + +#sub newHeader +#{ +# my $self = shift ; +# #return GZIP_MINIMUM_HEADER ; +# return $self->mkHeader(*$self->{Got}); +#} + +sub getExtraParams +{ + my $self = shift ; + + return ( + # zlib behaviour + $self->getZlibParams(), + + # Gzip header fields + 'Minimal' => [0, 1, Parse_boolean, 0], + 'Comment' => [0, 1, Parse_any, undef], + 'Name' => [0, 1, Parse_any, undef], + 'Time' => [0, 1, Parse_any, undef], + 'TextFlag' => [0, 1, Parse_boolean, 0], + 'HeaderCRC' => [0, 1, Parse_boolean, 0], + 'OS_Code' => [0, 1, Parse_unsigned, $Compress::Raw::Zlib::gzip_os_code], + 'ExtraField'=> [0, 1, Parse_any, undef], + 'ExtraFlags'=> [0, 1, Parse_any, undef], + + ); +} + + +sub ckParams +{ + my $self = shift ; + my $got = shift ; + + # gzip always needs crc32 + $got->value('CRC32' => 1); + + return 1 + if $got->value('Merge') ; + + my $strict = $got->value('Strict') ; + + + { + if (! $got->parsed('Time') ) { + # Modification time defaults to now. + $got->value('Time' => time) ; + } + + # Check that the Name & Comment don't have embedded NULLs + # Also check that they only contain ISO 8859-1 chars. + if ($got->parsed('Name') && defined $got->value('Name')) { + my $name = $got->value('Name'); + + return $self->saveErrorString(undef, "Null Character found in Name", + Z_DATA_ERROR) + if $strict && $name =~ /\x00/ ; + + return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Name", + Z_DATA_ERROR) + if $strict && $name =~ /$GZIP_FNAME_INVALID_CHAR_RE/o ; + } + + if ($got->parsed('Comment') && defined $got->value('Comment')) { + my $comment = $got->value('Comment'); + + return $self->saveErrorString(undef, "Null Character found in Comment", + Z_DATA_ERROR) + if $strict && $comment =~ /\x00/ ; + + return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Comment", + Z_DATA_ERROR) + if $strict && $comment =~ /$GZIP_FCOMMENT_INVALID_CHAR_RE/o; + } + + if ($got->parsed('OS_Code') ) { + my $value = $got->value('OS_Code'); + + return $self->saveErrorString(undef, "OS_Code must be between 0 and 255, got '$value'") + if $value < 0 || $value > 255 ; + + } + + # gzip only supports Deflate at present + $got->value('Method' => Z_DEFLATED) ; + + if ( ! $got->parsed('ExtraFlags')) { + $got->value('ExtraFlags' => 2) + if $got->value('Level') == Z_BEST_SPEED ; + $got->value('ExtraFlags' => 4) + if $got->value('Level') == Z_BEST_COMPRESSION ; + } + + my $data = $got->value('ExtraField') ; + if (defined $data) { + my $bad = IO::Compress::Zlib::Extra::parseExtraField($data, $strict, 1) ; + return $self->saveErrorString(undef, "Error with ExtraField Parameter: $bad", Z_DATA_ERROR) + if $bad ; + + $got->value('ExtraField', $data) ; + } + } + + return 1; +} + +sub mkTrailer +{ + my $self = shift ; + return pack("V V", *$self->{Compress}->crc32(), + *$self->{UnCompSize}->get32bit()); +} + +sub getInverseClass +{ + return ('IO::Uncompress::Gunzip', + \$IO::Uncompress::Gunzip::GunzipError); +} + +sub getFileInfo +{ + my $self = shift ; + my $params = shift; + my $filename = shift ; + + my $defaultTime = (stat($filename))[9] ; + + $params->value('Name' => $filename) + if ! $params->parsed('Name') ; + + $params->value('Time' => $defaultTime) + if ! $params->parsed('Time') ; +} + + +sub mkHeader +{ + my $self = shift ; + my $param = shift ; + + # stort-circuit if a minimal header is requested. + return GZIP_MINIMUM_HEADER if $param->value('Minimal') ; + + # METHOD + my $method = $param->valueOrDefault('Method', GZIP_CM_DEFLATED) ; + + # FLAGS + my $flags = GZIP_FLG_DEFAULT ; + $flags |= GZIP_FLG_FTEXT if $param->value('TextFlag') ; + $flags |= GZIP_FLG_FHCRC if $param->value('HeaderCRC') ; + $flags |= GZIP_FLG_FEXTRA if $param->wantValue('ExtraField') ; + $flags |= GZIP_FLG_FNAME if $param->wantValue('Name') ; + $flags |= GZIP_FLG_FCOMMENT if $param->wantValue('Comment') ; + + # MTIME + my $time = $param->valueOrDefault('Time', GZIP_MTIME_DEFAULT) ; + + # EXTRA FLAGS + my $extra_flags = $param->valueOrDefault('ExtraFlags', GZIP_XFL_DEFAULT); + + # OS CODE + my $os_code = $param->valueOrDefault('OS_Code', GZIP_OS_DEFAULT) ; + + + my $out = pack("C4 V C C", + GZIP_ID1, # ID1 + GZIP_ID2, # ID2 + $method, # Compression Method + $flags, # Flags + $time, # Modification Time + $extra_flags, # Extra Flags + $os_code, # Operating System Code + ) ; + + # EXTRA + if ($flags & GZIP_FLG_FEXTRA) { + my $extra = $param->value('ExtraField') ; + $out .= pack("v", length $extra) . $extra ; + } + + # NAME + if ($flags & GZIP_FLG_FNAME) { + my $name .= $param->value('Name') ; + $name =~ s/\x00.*$//; + $out .= $name ; + # Terminate the filename with NULL unless it already is + $out .= GZIP_NULL_BYTE + if !length $name or + substr($name, 1, -1) ne GZIP_NULL_BYTE ; + } + + # COMMENT + if ($flags & GZIP_FLG_FCOMMENT) { + my $comment .= $param->value('Comment') ; + $comment =~ s/\x00.*$//; + $out .= $comment ; + # Terminate the comment with NULL unless it already is + $out .= GZIP_NULL_BYTE + if ! length $comment or + substr($comment, 1, -1) ne GZIP_NULL_BYTE; + } + + # HEADER CRC + $out .= pack("v", crc32($out) & 0x00FF ) if $param->value('HeaderCRC') ; + + noUTF8($out); + + return $out ; +} + +sub mkFinalTrailer +{ + return ''; +} + +1; + +__END__ + +=head1 NAME + +IO::Compress::Gzip - Write RFC 1952 files/buffers + + + +=head1 SYNOPSIS + + use IO::Compress::Gzip qw(gzip $GzipError) ; + + my $status = gzip $input => $output [,OPTS] + or die "gzip failed: $GzipError\n"; + + my $z = new IO::Compress::Gzip $output [,OPTS] + or die "gzip failed: $GzipError\n"; + + $z->print($string); + $z->printf($format, $string); + $z->write($string); + $z->syswrite($string [, $length, $offset]); + $z->flush(); + $z->tell(); + $z->eof(); + $z->seek($position, $whence); + $z->binmode(); + $z->fileno(); + $z->opened(); + $z->autoflush(); + $z->input_line_number(); + $z->newStream( [OPTS] ); + + $z->deflateParams(); + + $z->close() ; + + $GzipError ; + + # IO::File mode + + print $z $string; + printf $z $format, $string; + tell $z + eof $z + seek $z, $position, $whence + binmode $z + fileno $z + close $z ; + + +=head1 DESCRIPTION + +This module provides a Perl interface that allows writing compressed +data to files or buffer as defined in RFC 1952. + +All the gzip headers defined in RFC 1952 can be created using +this module. + +For reading RFC 1952 files/buffers, see the companion module +L. + +=head1 Functional Interface + +A top-level function, C, is provided to carry out +"one-shot" compression between buffers and/or files. For finer +control over the compression process, see the L +section. + + use IO::Compress::Gzip qw(gzip $GzipError) ; + + gzip $input => $output [,OPTS] + or die "gzip failed: $GzipError\n"; + +The functional interface needs Perl5.005 or better. + +=head2 gzip $input => $output [, OPTS] + +C expects at least two parameters, C<$input> and C<$output>. + +=head3 The C<$input> parameter + +The parameter, C<$input>, is used to define the source of +the uncompressed data. + +It can take one of the following forms: + +=over 5 + +=item A filename + +If the C<$input> parameter is a simple scalar, it is assumed to be a +filename. This file will be opened for reading and the input data +will be read from it. + +=item A filehandle + +If the C<$input> parameter is a filehandle, the input data will be +read from it. +The string '-' can be used as an alias for standard input. + +=item A scalar reference + +If C<$input> is a scalar reference, the input data will be read +from C<$$input>. + +=item An array reference + +If C<$input> is an array reference, each element in the array must be a +filename. + +The input data will be read from each file in turn. + +The complete array will be walked to ensure that it only +contains valid filenames before any data is compressed. + +=item An Input FileGlob string + +If C<$input> is a string that is delimited by the characters "<" and ">" +C will assume that it is an I. The +input is the list of files that match the fileglob. + +If the fileglob does not match any files ... + +See L for more details. + +=back + +If the C<$input> parameter is any other type, C will be returned. + +In addition, if C<$input> is a simple filename, the default values for +the C and C