📄 compress::zlib.3
字号:
When a dictionary is specified \fICompress::Zlib\fR will automaticallycall \f(CW\*(C`deflateSetDictionary\*(C'\fR directly after calling \f(CW\*(C`deflateInit\*(C'\fR. TheAdler32 value for the dictionary can be obtained by calling the method \&\f(CW\*(C`$d\-\*(C'\fR\fIdict_adler()\fR>..SpThe default is no dictionary..IP "\fB\-Bufsize\fR" 5.IX Item "-Bufsize"Sets the initial size for the deflation buffer. If the buffer has to bereallocated to increase the size, it will grow in increments of\&\f(CW\*(C`Bufsize\*(C'\fR..SpThe default is 4096..PPHere is an example of using the \f(CW\*(C`deflateInit\*(C'\fR optional parameter listto override the default buffer size and compression level. All otheroptions will take their default values..PP.Vb 2\& deflateInit( \-Bufsize => 300, \& \-Level => Z_BEST_SPEED ) ;.Ve.ie n .Sh "\fB($out, \fP\fB$status\fP\fB) = \fP\f(BI$d\fP\fB\->deflate($buffer)\fP".el .Sh "\fB($out, \fP\f(CB$status\fP\fB) = \fP\f(CB$d\fP\fB\->deflate($buffer)\fP".IX Subsection "($out, $status) = $d->deflate($buffer)"Deflates the contents of \f(CW$buffer\fR. The buffer can either be a scalaror a scalar reference. When finished, \f(CW$buffer\fR will becompletely processed (assuming there were no errors). If the deflationwas successful it returns the deflated output, \f(CW$out\fR, and a statusvalue, \f(CW$status\fR, of \f(CW\*(C`Z_OK\*(C'\fR..PPOn error, \f(CW$out\fR will be \fIundef\fR and \f(CW$status\fR will contain the\&\fIzlib\fR error code..PPIn a scalar context \f(CW\*(C`deflate\*(C'\fR will return \f(CW$out\fR only..PPAs with the \fIdeflate\fR function in \fIzlib\fR, it is not necessarily thecase that any output will be produced by this method. So don't rely onthe fact that \f(CW$out\fR is empty for an error test..ie n .Sh "\fB($out, \fP\fB$status\fP\fB) = \fP\f(BI$d\fP\fB\->flush([flush_type])\fP".el .Sh "\fB($out, \fP\f(CB$status\fP\fB) = \fP\f(CB$d\fP\fB\->flush([flush_type])\fP".IX Subsection "($out, $status) = $d->flush([flush_type])"Typically used to finish the deflation. Any pending output will bereturned via \f(CW$out\fR.\&\f(CW$status\fR will have a value \f(CW\*(C`Z_OK\*(C'\fR if successful..PPIn a scalar context \f(CW\*(C`flush\*(C'\fR will return \f(CW$out\fR only..PPNote that flushing can seriously degrade the compression ratio, so itshould only be used to terminate a decompression (using \f(CW\*(C`Z_FINISH\*(C'\fR) orwhen you want to create a \fIfull flush point\fR (using \f(CW\*(C`Z_FULL_FLUSH\*(C'\fR)..PPBy default the \f(CW\*(C`flush_type\*(C'\fR used is \f(CW\*(C`Z_FINISH\*(C'\fR. Other valid valuesfor \f(CW\*(C`flush_type\*(C'\fR are \f(CW\*(C`Z_NO_FLUSH\*(C'\fR, \f(CW\*(C`Z_PARTIAL_FLUSH\*(C'\fR, \f(CW\*(C`Z_SYNC_FLUSH\*(C'\fRand \f(CW\*(C`Z_FULL_FLUSH\*(C'\fR. It is strongly recommended that you only set the\&\f(CW\*(C`flush_type\*(C'\fR parameter if you fully understand the implications ofwhat it does. See the \f(CW\*(C`zlib\*(C'\fR documentation for details..ie n .Sh "\fB\fP\fB$status\fP\fB = \fP\f(BI$d\fP\fB\->deflateParams([\s-1OPT\s0])\fP".el .Sh "\fB\fP\f(CB$status\fP\fB = \fP\f(CB$d\fP\fB\->deflateParams([\s-1OPT\s0])\fP".IX Subsection "$status = $d->deflateParams([OPT])"Change settings for the deflate stream \f(CW$d\fR..PPThe list of the valid options is shown below. Options not specifiedwill remain unchanged..IP "\fB\-Level\fR" 5.IX Item "-Level"Defines the compression level. Valid values are 0 through 9,\&\f(CW\*(C`Z_NO_COMPRESSION\*(C'\fR, \f(CW\*(C`Z_BEST_SPEED\*(C'\fR, \f(CW\*(C`Z_BEST_COMPRESSION\*(C'\fR, and\&\f(CW\*(C`Z_DEFAULT_COMPRESSION\*(C'\fR..IP "\fB\-Strategy\fR" 5.IX Item "-Strategy"Defines the strategy used to tune the compression. The valid values are\&\f(CW\*(C`Z_DEFAULT_STRATEGY\*(C'\fR, \f(CW\*(C`Z_FILTERED\*(C'\fR and \f(CW\*(C`Z_HUFFMAN_ONLY\*(C'\fR..ie n .Sh "\fB\fP\fB$d\fP\fB\->\fP\f(BIdict_adler()\fP\fB\fP".el .Sh "\fB\fP\f(CB$d\fP\fB\->\fP\f(BIdict_adler()\fP\fB\fP".IX Subsection "$d->dict_adler()"Returns the adler32 value for the dictionary..ie n .Sh "\fB\fP\fB$d\fP\fB\->\fP\f(BImsg()\fP\fB\fP".el .Sh "\fB\fP\f(CB$d\fP\fB\->\fP\f(BImsg()\fP\fB\fP".IX Subsection "$d->msg()"Returns the last error message generated by zlib..ie n .Sh "\fB\fP\fB$d\fP\fB\->\fP\f(BItotal_in()\fP\fB\fP".el .Sh "\fB\fP\f(CB$d\fP\fB\->\fP\f(BItotal_in()\fP\fB\fP".IX Subsection "$d->total_in()"Returns the total number of bytes uncompressed bytes input to deflate..ie n .Sh "\fB\fP\fB$d\fP\fB\->\fP\f(BItotal_out()\fP\fB\fP".el .Sh "\fB\fP\f(CB$d\fP\fB\->\fP\f(BItotal_out()\fP\fB\fP".IX Subsection "$d->total_out()"Returns the total number of compressed bytes output from deflate..Sh "Example".IX Subsection "Example"Here is a trivial example of using \f(CW\*(C`deflate\*(C'\fR. It simply reads standardinput, deflates it and writes it to standard output..PP.Vb 2\& use strict ;\& use warnings ;\&\& use Compress::Zlib ;\&\& binmode STDIN;\& binmode STDOUT;\& my $x = deflateInit()\& or die "Cannot create a deflation stream\en" ;\&\& my ($output, $status) ;\& while (<>)\& {\& ($output, $status) = $x\->deflate($_) ;\& \& $status == Z_OK\& or die "deflation failed\en" ;\& \& print $output ;\& }\& \& ($output, $status) = $x\->flush() ;\& \& $status == Z_OK\& or die "deflation failed\en" ;\& \& print $output ;.Ve.SH "Inflate Interface".IX Header "Inflate Interface"This section defines the interface available that allows in-memoryuncompression using the \fIdeflate\fR interface provided by zlib..PPHere is a definition of the interface:.ie n .Sh "\fB($i, \fP\fB$status\fP\fB) = \fP\f(BIinflateInit()\fP\fB\fP".el .Sh "\fB($i, \fP\f(CB$status\fP\fB) = \fP\f(BIinflateInit()\fP\fB\fP".IX Subsection "($i, $status) = inflateInit()"Initialises an inflation stream..PPIn a list context it returns the inflation stream, \f(CW$i\fR, and the\&\fIzlib\fR status code in \f(CW$status\fR. In a scalar context it returns theinflation stream only..PPIf successful, \f(CW$i\fR will hold the inflation stream and \f(CW$status\fR willbe \f(CW\*(C`Z_OK\*(C'\fR..PPIf not successful, \f(CW$i\fR will be \fIundef\fR and \f(CW$status\fR will hold the\&\fIzlib\fR error code..PPThe function optionally takes a number of named options specified as\&\f(CW\*(C`\-Name=>value\*(C'\fR pairs. This allows individual options to betailored without having to specify them all in the parameter list..PPFor backward compatibility, it is also possible to pass the parametersas a reference to a hash containing the name=>value pairs..PPThe function takes one optional parameter, a reference to a hash. Thecontents of the hash allow the deflation interface to be tailored..PPHere is a list of the valid options:.IP "\fB\-WindowBits\fR" 5.IX Item "-WindowBits"To uncompress an \s-1RFC\s0 1950 data stream, set \f(CW\*(C`WindowBits\*(C'\fR to a positive number..SpTo uncompress an \s-1RFC\s0 1951 data stream, set \f(CW\*(C`WindowBits\*(C'\fR to \f(CW\*(C`\-MAX_WBITS\*(C'\fR..SpFor a full definition of the meaning and valid values for \f(CW\*(C`WindowBits\*(C'\fR referto the \fIzlib\fR documentation for \fIinflateInit2\fR..SpDefaults to \s-1MAX_WBITS\s0..IP "\fB\-Bufsize\fR" 5.IX Item "-Bufsize"Sets the initial size for the inflation buffer. If the buffer has to bereallocated to increase the size, it will grow in increments of\&\f(CW\*(C`Bufsize\*(C'\fR..SpDefault is 4096..IP "\fB\-Dictionary\fR" 5.IX Item "-Dictionary"The default is no dictionary..PPHere is an example of using the \f(CW\*(C`inflateInit\*(C'\fR optional parameter tooverride the default buffer size..PP.Vb 1\& inflateInit( \-Bufsize => 300 ) ;.Ve.ie n .Sh "\fB($out, \fP\fB$status\fP\fB) = \fP\f(BI$i\fP\fB\->inflate($buffer)\fP".el .Sh "\fB($out, \fP\f(CB$status\fP\fB) = \fP\f(CB$i\fP\fB\->inflate($buffer)\fP".IX Subsection "($out, $status) = $i->inflate($buffer)"Inflates the complete contents of \f(CW$buffer\fR. The buffer can either bea scalar or a scalar reference..PPReturns \f(CW\*(C`Z_OK\*(C'\fR if successful and \f(CW\*(C`Z_STREAM_END\*(C'\fR if the end of thecompressed data has been successfully reached. If not successful, \f(CW$out\fR will be \fIundef\fR and \f(CW$status\fR will holdthe \fIzlib\fR error code..PPThe \f(CW$buffer\fR parameter is modified by \f(CW\*(C`inflate\*(C'\fR. On completion itwill contain what remains of the input buffer after inflation. Thismeans that \f(CW$buffer\fR will be an empty string when the return status is\&\f(CW\*(C`Z_OK\*(C'\fR. When the return status is \f(CW\*(C`Z_STREAM_END\*(C'\fR the \f(CW$buffer\fRparameter will contains what (if anything) was stored in the inputbuffer after the deflated data stream..PPThis feature is useful when processing a file format that encapsulatesa compressed data stream (e.g. gzip, zip)..ie n .Sh "\fB\fP\fB$status\fP\fB = \fP\f(BI$i\fP\fB\->inflateSync($buffer)\fP".el .Sh "\fB\fP\f(CB$status\fP\fB = \fP\f(CB$i\fP\fB\->inflateSync($buffer)\fP".IX Subsection "$status = $i->inflateSync($buffer)"Scans \f(CW$buffer\fR until it reaches either a \fIfull flush point\fR or theend of the buffer..PPIf a \fIfull flush point\fR is found, \f(CW\*(C`Z_OK\*(C'\fR is returned and \f(CW$buffer\fRwill be have all data up to the flush point removed. This can then bepassed to the \f(CW\*(C`deflate\*(C'\fR method..PPAny other return code means that a flush point was not found. If moredata is available, \f(CW\*(C`inflateSync\*(C'\fR can be called repeatedly with morecompressed data until the flush point is found..ie n .Sh "\fB\fP\fB$i\fP\fB\->\fP\f(BIdict_adler()\fP\fB\fP".el .Sh "\fB\fP\f(CB$i\fP\fB\->\fP\f(BIdict_adler()\fP\fB\fP".IX Subsection "$i->dict_adler()"Returns the adler32 value for the dictionary..ie n .Sh "\fB\fP\fB$i\fP\fB\->\fP\f(BImsg()\fP\fB\fP".el .Sh "\fB\fP\f(CB$i\fP\fB\->\fP\f(BImsg()\fP\fB\fP".IX Subsection "$i->msg()"Returns the last error message generated by zlib..ie n .Sh "\fB\fP\fB$i\fP\fB\->\fP\f(BItotal_in()\fP\fB\fP".el .Sh "\fB\fP\f(CB$i\fP\fB\->\fP\f(BItotal_in()\fP\fB\fP".IX Subsection "$i->total_in()"Returns the total number of bytes compressed bytes input to inflate..ie n .Sh "\fB\fP\fB$i\fP\fB\->\fP\f(BItotal_out()\fP\fB\fP".el .Sh "\fB\fP\f(CB$i\fP\fB\->\fP\f(BItotal_out()\fP\fB\fP".IX Subsection "$i->total_out()"Returns the total number of uncompressed bytes output from inflate..Sh "Example".IX Subsection "Example"Here is an example of using \f(CW\*(C`inflate\*(C'\fR..PP.Vb 2\& use strict ;\& use warnings ;\& \& use Compress::Zlib ;\& \& my $x = inflateInit()\& or die "Cannot create a inflation stream\en" ;\& \& my $input = \*(Aq\*(Aq ;\& binmode STDIN;\& binmode STDOUT;\& \& my ($output, $status) ;\& while (read(STDIN, $input, 4096))\& {\& ($output, $status) = $x\->inflate(\e$input) ;\& \& print $output \& if $status == Z_OK or $status == Z_STREAM_END ;\& \& last if $status != Z_OK ;\& }\& \& die "inflation failed\en"\& unless $status == Z_STREAM_END ;.Ve.SH "CHECKSUM FUNCTIONS".IX Header "CHECKSUM FUNCTIONS"Two functions are provided by \fIzlib\fR to calculate checksums. For thePerl interface, the order of the two parameters in both functions hasbeen reversed. This allows both running checksums and one offcalculations to be done..PP.Vb 2\& $crc = adler32($buffer [,$crc]) ;\& $crc = crc32($buffer [,$crc]) ;.Ve.PPThe buffer parameters can either be a scalar or a scalar reference..PPIf the \f(CW$crc\fR parameters is \f(CW\*(C`undef\*(C'\fR, the crc value will be reset..PPIf you have built this module with zlib 1.2.3 or better, two moreCRC-related functions are available..PP.Vb 2\& $crc = adler32_combine($crc1, $crc2, $len2)l\& $crc = crc32_combine($adler1, $adler2, $len2).Ve.PPThese functions allow checksums to be merged..SH "CONSTANTS".IX Header "CONSTANTS"All the \fIzlib\fR constants are automatically imported when you make useof \fICompress::Zlib\fR..SH "SEE ALSO".IX Header "SEE ALSO"IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate, IO::Uncompress::Inflate, IO::Compress::RawDeflate, IO::Uncompress::RawInflate, IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Uncompress::AnyInflate, IO::Uncompress::AnyUncompress.PPCompress::Zlib::FAQ.PPFile::GlobMapper, Archive::Zip,Archive::Tar,IO::Zlib.PPFor \s-1RFC\s0 1950, 1951 and 1952 see \&\fIhttp://www.faqs.org/rfcs/rfc1950.html\fR,\&\fIhttp://www.faqs.org/rfcs/rfc1951.html\fR and\&\fIhttp://www.faqs.org/rfcs/rfc1952.html\fR.PPThe \fIzlib\fR compression library was written by Jean-loup Gailly\&\fIgzip@prep.ai.mit.edu\fR and Mark Adler \fImadler@alumni.caltech.edu\fR..PPThe primary site for the \fIzlib\fR compression library is\&\fIhttp://www.zlib.org\fR..PPThe primary site for gzip is \fIhttp://www.gzip.org\fR..SH "AUTHOR".IX Header "AUTHOR"This module was written by Paul Marquess, \fIpmqs@cpan.org\fR..SH "MODIFICATION HISTORY".IX Header "MODIFICATION HISTORY"See the Changes file..SH "COPYRIGHT AND LICENSE".IX Header "COPYRIGHT AND LICENSE"Copyright (c) 1995\-2007 Paul Marquess. All rights reserved..PPThis program is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -