compress::raw::zlib.3
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· 3 代码 · 共 753 行 · 第 1/3 页
3
753 行
If the option is set to false, the output buffer in the \f(CW\*(C`$i\->inflate\*(C'\fRmethod will be truncated before uncompressed data is written to it..SpIf the option is set to true, uncompressed data will be appended to theoutput buffer by the \f(CW\*(C`$i\->inflate\*(C'\fR method..SpThis option defaults to false..IP "\fB\-CRC32\fR" 5.IX Item "-CRC32"If set to true, a crc32 checksum of the uncompressed data will becalculated. Use the \f(CW\*(C`$i\->crc32\*(C'\fR method to retrieve this value..SpThis option defaults to false..IP "\fB\-ADLER32\fR" 5.IX Item "-ADLER32"If set to true, an adler32 checksum of the uncompressed data will becalculated. Use the \f(CW\*(C`$i\->adler32\*(C'\fR method to retrieve this value..SpThis option defaults to false..IP "\fB\-ConsumeInput\fR" 5.IX Item "-ConsumeInput"If set to true, this option will remove compressed data from the inputbuffer of the the \f(CW\*(C` $i\->inflate \*(C'\fR method as the inflate progresses..SpThis option can be useful when you are processing compressed data that isembedded in another file/buffer. In this case the data that immediatelyfollows the compressed stream will be left in the input buffer..SpThis option defaults to true..PPHere is an example of using an optional parameter to override the defaultbuffer size..PP.Vb 1\& my ($i, $status) = new Compress::Raw::Zlib::Inflate( \-Bufsize => 300 ) ;.Ve.ie n .Sh "\fB \fP\fB$status\fP\fB = \fP\f(BI$i\fP\fB\->inflate($input, \fP\f(CB$output\fP\fB [,$eof]) \fP".el .Sh "\fB \fP\f(CB$status\fP\fB = \fP\f(CB$i\fP\fB\->inflate($input, \fP\f(CB$output\fP\fB [,$eof]) \fP".IX Subsection " $status = $i->inflate($input, $output [,$eof]) "Inflates the complete contents of \f(CW$input\fR and writes the uncompresseddata to \f(CW$output\fR. The \f(CW$input\fR and \f(CW$output\fR parameters can either bescalars or scalar references..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..PPIf not successful \f(CW$status\fR will hold the \fIzlib\fR error code..PPIf the \f(CW\*(C`ConsumeInput\*(C'\fR option has been set to true when the\&\f(CW\*(C`Compress::Raw::Zlib::Inflate\*(C'\fR object is created, the \f(CW$input\fR parameteris modified by \f(CW\*(C`inflate\*(C'\fR. On completion it will contain what remainsof the input buffer after inflation. In practice, this means that whenthe return status is \f(CW\*(C`Z_OK\*(C'\fR the \f(CW$input\fR parameter will contain anempty string, and when the return status is \f(CW\*(C`Z_STREAM_END\*(C'\fR the \f(CW$input\fRparameter will contains what (if anything) was stored in the input bufferafter the deflated data stream..PPThis feature is useful when processing a file format that encapsulatesa compressed data stream (e.g. gzip, zip) and there is useful dataimmediately after the deflation stream..PPIf the \f(CW\*(C`AppendOutput\*(C'\fR option is set to true in the constructor forthis object, the uncompressed data will be appended to \f(CW$output\fR. Ifit is false, \f(CW$output\fR will be truncated before any uncompressed datais written to it..PPThe \f(CW$eof\fR parameter needs a bit of explanation..PPPrior to version 1.2.0, zlib assumed that there was at least one trailingbyte immediately after the compressed data stream when it was carrying outdecompression. This normally isn't a problem because the majority of zlibapplications guarantee that there will be data directly after thecompressed data stream. For example, both gzip (\s-1RFC\s0 1950) and zip bothdefine trailing data that follows the compressed data stream..PPThe \f(CW$eof\fR parameter only needs to be used if \fBall\fR of the followingconditions apply.IP "1." 5You are either using a copy of zlib that is older than version 1.2.0 or youwant your application code to be able to run with as many differentversions of zlib as possible..IP "2." 5You have set the \f(CW\*(C`WindowBits\*(C'\fR parameter to \f(CW\*(C`\-MAX_WBITS\*(C'\fR in the constructorfor this object, i.e. you are uncompressing a raw deflated data stream(\s-1RFC\s0 1951)..IP "3." 5There is no data immediately after the compressed data stream..PPIf \fBall\fR of these are the case, then you need to set the \f(CW$eof\fR parameterto true on the final call (and only the final call) to \f(CW\*(C`$i\->inflate\*(C'\fR..PPIf you have built this module with zlib >= 1.2.0, the \f(CW$eof\fR parameter isignored. You can still set it if you want, but it won't be used behind thescenes..ie n .Sh "\fB\fP\fB$status\fP\fB = \fP\f(BI$i\fP\fB\->inflateSync($input)\fP".el .Sh "\fB\fP\f(CB$status\fP\fB = \fP\f(CB$i\fP\fB\->inflateSync($input)\fP".IX Subsection "$status = $i->inflateSync($input)"This method can be used to attempt to recover good data from a compresseddata stream that is partially corrupt.It scans \f(CW$input\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$input\fRwill be have all data up to the flush point removed. This data can then bepassed to the \f(CW\*(C`$i\->inflate\*(C'\fR method to be uncompressed..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..PPNote \fIfull flush points\fR are not present by default in compresseddata streams. They must have been added explicitly when the data streamwas created by calling \f(CW\*(C`Compress::Deflate::flush\*(C'\fR with \f(CW\*(C`Z_FULL_FLUSH\*(C'\fR..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(BIcrc32()\fP\fB\fP".el .Sh "\fB\fP\f(CB$i\fP\fB\->\fP\f(BIcrc32()\fP\fB\fP".IX Subsection "$i->crc32()"Returns the crc32 value for the uncompressed data to date..PPIf the \f(CW\*(C`CRC32\*(C'\fR option is not enabled in the constructor for this object,this method will always return 0;.ie n .Sh "\fB\fP\fB$i\fP\fB\->\fP\f(BIadler32()\fP\fB\fP".el .Sh "\fB\fP\f(CB$i\fP\fB\->\fP\f(BIadler32()\fP\fB\fP".IX Subsection "$i->adler32()"Returns the adler32 value for the uncompressed data to date..PPIf the \f(CW\*(C`ADLER32\*(C'\fR option is not enabled in the constructor for this object,this method will always return 0;.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..ie n .Sh "\fB\fP\fB$d\fP\fB\->\fP\f(BIget_BufSize()\fP\fB\fP".el .Sh "\fB\fP\f(CB$d\fP\fB\->\fP\f(BIget_BufSize()\fP\fB\fP".IX Subsection "$d->get_BufSize()"Returns the buffer size used to carry out the decompression..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::Raw::Zlib;\& \& my $x = new Compress::Raw::Zlib::Inflate()\& or die "Cannot create a inflation stream\en" ;\& \& my $input = \*(Aq\*(Aq ;\& binmode STDIN;\& binmode STDOUT;\& \& my ($output, $status) ;\& while (read(STDIN, $input, 4096))\& {\& $status = $x\->inflate(\e$input, $output) ;\& \& 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 "ACCESSING ZIP FILES".IX Header "ACCESSING ZIP FILES"Although it is possible (with some effort on your part) to use thismodule to access .zip files, there is a module on \s-1CPAN\s0 that will do allthe hard work for you. Check out the \f(CW\*(C`Archive::Zip\*(C'\fR module on \s-1CPAN\s0 at.PP.Vb 1\& http://www.cpan.org/modules/by\-module/Archive/Archive\-Zip\-*.tar.gz.Ve.SH "CONSTANTS".IX Header "CONSTANTS"All the \fIzlib\fR constants are automatically imported when you make useof \fICompress::Raw::Zlib\fR..SH "SEE ALSO".IX Header "SEE ALSO"Compress::Zlib, 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) 2005\-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 + =
减小字号Ctrl + -
显示快捷键?