⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zlib.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 3 页
字号:
undef.The C<$buffer> parameter can either be a scalar or a scalar reference.See L<IO::Compress::Gzip|IO::Compress::Gzip> for an alternative way tocarry out in-memory gzip compression.=head2 Compress::Zlib::memGunzipThis function is used to uncompress an in-memory gzip file.    $dest = Compress::Zlib::memGunzip($buffer) ;If successful, it returns the uncompressed gzip file, otherwise itreturns undef.The C<$buffer> parameter can either be a scalar or a scalar reference. Thecontents of the C<$buffer> parameter are destroyed after calling this function.See L<IO::Uncompress::Gunzip|IO::Uncompress::Gunzip> for an alternative wayto carry out in-memory gzip uncompression.=head1 COMPRESS/UNCOMPRESSTwo functions are provided to perform in-memory compression/uncompression ofRFC 1950 data streams. They are called C<compress> and C<uncompress>.=over 5=item B<$dest = compress($source [, $level] ) ;>Compresses C<$source>. If successful it returns the compresseddata. Otherwise it returns I<undef>.The source buffer, C<$source>, can either be a scalar or a scalarreference.The C<$level> parameter defines the compression level. Valid values are0 through 9, C<Z_NO_COMPRESSION>, C<Z_BEST_SPEED>,C<Z_BEST_COMPRESSION>, and C<Z_DEFAULT_COMPRESSION>.If C<$level> is not specified C<Z_DEFAULT_COMPRESSION> will be used.=item B<$dest = uncompress($source) ;>Uncompresses C<$source>. If successful it returns the uncompresseddata. Otherwise it returns I<undef>.The source buffer can either be a scalar or a scalar reference.=backPlease note: the two functions defined above are I<not> compatible withthe Unix commands of the same name.See L<IO::Deflate|IO::Deflate> and L<IO::Inflate|IO::Inflate> included withthis distribution for an alternative interface for reading/writing RFC 1950files/buffers.=head1 Deflate InterfaceThis section defines an interface that allows in-memory compression usingthe I<deflate> 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<zlib> functions C<deflateInit>,C<deflateInit2> and C<deflateSetDictionary>.If successful, it will return the initialised deflation stream, C<$d>and C<$status> of C<Z_OK> in a list context. In scalar context itreturns the deflation stream, C<$d>, only.If not successful, the returned deflation stream (C<$d>) will beI<undef> and C<$status> will hold the exact I<zlib> error code.The function optionally takes a number of named options specified asC<< -Name=>value >> pairs. This allows individual options to betailored without having to specify them all in the parameter list.For backward compatibility, it is also possible to pass the parametersas a reference to a hash containing the name=>value pairs.The function takes one optional parameter, a reference to a hash.  Thecontents 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<Z_NO_COMPRESSION>, C<Z_BEST_SPEED>, C<Z_BEST_COMPRESSION>, andC<Z_DEFAULT_COMPRESSION>.The default is Z_DEFAULT_COMPRESSION.=item B<-Method>Defines the compression method. The only valid value at present (andthe default) is Z_DEFLATED.=item B<-WindowBits>To create an RFC 1950 data stream, set C<WindowBits> to a positive number.To create an RFC 1951 data stream, set C<WindowBits> to C<-MAX_WBITS>.For a full definition of the meaning and valid values for C<WindowBits> referto the I<zlib> documentation for I<deflateInit2>.Defaults to MAX_WBITS.=item B<-MemLevel>For a definition of the meaning and valid values for C<MemLevel>refer to the I<zlib> documentation for I<deflateInit2>.Defaults to MAX_MEM_LEVEL.=item B<-Strategy>Defines the strategy used to tune the compression. The valid values areC<Z_DEFAULT_STRATEGY>, C<Z_FILTERED> and C<Z_HUFFMAN_ONLY>. The default is Z_DEFAULT_STRATEGY.=item B<-Dictionary>When a dictionary is specified I<Compress::Zlib> will automaticallycall C<deflateSetDictionary> directly after calling C<deflateInit>. TheAdler32 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 bereallocated to increase the size, it will grow in increments ofC<Bufsize>.The default is 4096.=backHere is an example of using the C<deflateInit> optional parameter listto override the default buffer size and compression level. All otheroptions will take their default values.    deflateInit( -Bufsize => 300,                  -Level => Z_BEST_SPEED  ) ;=head2 B<($out, $status) = $d-E<gt>deflate($buffer)>Deflates the contents of C<$buffer>. The buffer can either be a scalaror a scalar reference.  When finished, C<$buffer> will becompletely processed (assuming there were no errors). If the deflationwas successful it returns the deflated output, C<$out>, and a statusvalue, C<$status>, of C<Z_OK>.On error, C<$out> will be I<undef> and C<$status> will contain theI<zlib> error code.In a scalar context C<deflate> will return C<$out> only.As with the I<deflate> function in I<zlib>, it is not necessarily thecase that any output will be produced by this method. So don't rely onthe fact that C<$out> is empty for an error test.=head2 B<($out, $status) = $d-E<gt>flush([flush_type])>Typically used to finish the deflation. Any pending output will bereturned via C<$out>.C<$status> will have a value C<Z_OK> if successful.In a scalar context C<flush> will return C<$out> only.Note that flushing can seriously degrade the compression ratio, so itshould only be used to terminate a decompression (using C<Z_FINISH>) orwhen you want to create a I<full flush point> (using C<Z_FULL_FLUSH>).By default the C<flush_type> used is C<Z_FINISH>. Other valid valuesfor C<flush_type> are C<Z_NO_FLUSH>, C<Z_PARTIAL_FLUSH>, C<Z_SYNC_FLUSH>and C<Z_FULL_FLUSH>. It is strongly recommended that you only set theC<flush_type> parameter if you fully understand the implications ofwhat it does. See the C<zlib> documentation for details.=head2 B<$status = $d-E<gt>deflateParams([OPT])>Change settings for the deflate stream C<$d>.The list of the valid options is shown below. Options not specifiedwill remain unchanged.=over 5=item B<-Level>Defines the compression level. Valid values are 0 through 9,C<Z_NO_COMPRESSION>, C<Z_BEST_SPEED>, C<Z_BEST_COMPRESSION>, andC<Z_DEFAULT_COMPRESSION>.=item B<-Strategy>Defines the strategy used to tune the compression. The valid values areC<Z_DEFAULT_STRATEGY>, C<Z_FILTERED> and C<Z_HUFFMAN_ONLY>. =back=head2 B<$d-E<gt>dict_adler()>Returns the adler32 value for the dictionary.=head2 B<$d-E<gt>msg()>Returns the last error message generated by zlib.=head2 B<$d-E<gt>total_in()>Returns the total number of bytes uncompressed bytes input to deflate.=head2 B<$d-E<gt>total_out()>Returns the total number of compressed bytes output from deflate.=head2 ExampleHere is a trivial example of using C<deflate>. It simply reads standardinput, 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 InterfaceThis section defines the interface available that allows in-memoryuncompression using the I<deflate> 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 theI<zlib> status code in C<$status>. In a scalar context it returns theinflation stream only.If successful, C<$i> will hold the inflation stream and C<$status> willbe C<Z_OK>.If not successful, C<$i> will be I<undef> and C<$status> will hold theI<zlib> error code.The function optionally takes a number of named options specified asC<< -Name=>value >> pairs. This allows individual options to betailored without having to specify them all in the parameter list. For backward compatibility, it is also possible to pass the parametersas a reference to a hash containing the name=>value pairs. The function takes one optional parameter, a reference to a hash.  Thecontents 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<WindowBits> to a positive number.To uncompress an RFC 1951 data stream, set C<WindowBits> to C<-MAX_WBITS>.For a full definition of the meaning and valid values for C<WindowBits> referto the I<zlib> documentation for I<inflateInit2>.Defaults to MAX_WBITS.=item B<-Bufsize>Sets the initial size for the inflation buffer. If the buffer has to bereallocated to increase the size, it will grow in increments ofC<Bufsize>. Default is 4096.=item B<-Dictionary>The default is no dictionary.=backHere is an example of using the C<inflateInit> optional parameter tooverride the default buffer size.    inflateInit( -Bufsize => 300 ) ;=head2 B<($out, $status) = $i-E<gt>inflate($buffer)>Inflates the complete contents of C<$buffer>. The buffer can either bea scalar or a scalar reference.Returns C<Z_OK> if successful and C<Z_STREAM_END> if the end of thecompressed data has been successfully reached. If not successful, C<$out> will be I<undef> and C<$status> will holdthe I<zlib> error code.The C<$buffer> parameter is modified by C<inflate>. On completion itwill contain what remains of the input buffer after inflation. Thismeans that C<$buffer> will be an empty string when the return status isC<Z_OK>. When the return status is C<Z_STREAM_END> the C<$buffer>parameter will contains what (if anything) was stored in the inputbuffer after the deflated data stream.This feature is useful when processing a file format that encapsulatesa  compressed data stream (e.g. gzip, zip).=head2 B<$status = $i-E<gt>inflateSync($buffer)>Scans C<$buffer> until it reaches either a I<full flush point> or theend of the buffer.If a I<full flush point> is found, C<Z_OK> is returned and C<$buffer>will be have all data up to the flush point removed. This can then bepassed to the C<deflate> method.Any other return code means that a flush point was not found. If moredata is available, C<inflateSync> can be called repeatedly with morecompressed data until the flush point is found.=head2 B<$i-E<gt>dict_adler()>Returns the adler32 value for the dictionary.=head2 B<$i-E<gt>msg()>Returns the last error message generated by zlib.=head2 B<$i-E<gt>total_in()>Returns the total number of bytes compressed bytes input to inflate.=head2 B<$i-E<gt>total_out()>Returns the total number of uncompressed bytes output from inflate.=head2 ExampleHere is an example of using C<inflate>.    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 FUNCTIONSTwo functions are provided by I<zlib> 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.    $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<undef>, the crc value will be reset.If you have built this module with zlib 1.2.3 or better, two moreCRC-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 CONSTANTSAll the I<zlib> constants are automatically imported when you make useof I<Compress::Zlib>.=head1 SEE ALSOL<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,L<Archive::Tar|Archive::Tar>,L<IO::Zlib|IO::Zlib>For RFC 1950, 1951 and 1952 see F<http://www.faqs.org/rfcs/rfc1950.html>,F<http://www.faqs.org/rfcs/rfc1951.html> andF<http://www.faqs.org/rfcs/rfc1952.html>The I<zlib> compression library was written by Jean-loup GaillyF<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>.The primary site for the I<zlib> compression library isF<http://www.zlib.org>.The primary site for gzip is F<http://www.gzip.org>.=head1 AUTHORThis module was written by Paul Marquess, F<pmqs@cpan.org>. =head1 MODIFICATION HISTORYSee the Changes file.=head1 COPYRIGHT AND LICENSECopyright (c) 1995-2007 Paul Marquess. All rights reserved.This 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 + -