📄 zlib.pm
字号:
_inflateInit($flags, $got->value('WindowBits'), $got->value('Bufsize'), $got->value('Dictionary')) ;}sub Compress::Raw::Zlib::InflateScan::new{ my $pkg = shift ; my ($got) = ParseParameters(0, { 'CRC32' => [1, 1, Parse_boolean, 0], 'ADLER32' => [1, 1, Parse_boolean, 0], 'Bufsize' => [1, 1, Parse_unsigned, 4096], 'WindowBits' => [1, 1, Parse_signed, -MAX_WBITS()], 'Dictionary' => [1, 1, Parse_any, ""], }, @_) ; croak "Compress::Raw::Zlib::InflateScan::new: Bufsize must be >= 1, you specified " . $got->value('Bufsize') unless $got->value('Bufsize') >= 1; my $flags = 0 ; #$flags |= FLAG_APPEND if $got->value('AppendOutput') ; $flags |= FLAG_CRC if $got->value('CRC32') ; $flags |= FLAG_ADLER if $got->value('ADLER32') ; #$flags |= FLAG_CONSUME_INPUT if $got->value('ConsumeInput') ; _inflateScanInit($flags, $got->value('WindowBits'), $got->value('Bufsize'), '') ;}sub Compress::Raw::Zlib::inflateScanStream::createDeflateStream{ my $pkg = shift ; my ($got) = ParseParameters(0, { 'AppendOutput' => [1, 1, Parse_boolean, 0], 'CRC32' => [1, 1, Parse_boolean, 0], 'ADLER32' => [1, 1, Parse_boolean, 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()], }, @_) ; croak "Compress::Raw::Zlib::InflateScan::createDeflateStream: Bufsize must be >= 1, you specified " . $got->value('Bufsize') unless $got->value('Bufsize') >= 1; my $flags = 0 ; $flags |= FLAG_APPEND if $got->value('AppendOutput') ; $flags |= FLAG_CRC if $got->value('CRC32') ; $flags |= FLAG_ADLER if $got->value('ADLER32') ; $pkg->_createDeflateStream($flags, $got->value('Level'), $got->value('Method'), $got->value('WindowBits'), $got->value('MemLevel'), $got->value('Strategy'), $got->value('Bufsize'), ) ;}sub Compress::Raw::Zlib::inflateScanStream::inflate{ my $self = shift ; my $buffer = $_[1]; my $eof = $_[2]; my $status = $self->scan(@_); if ($status == Z_OK() && $_[2]) { my $byte = ' '; $status = $self->scan(\$byte, $_[1]) ; } return $status ;}sub Compress::Raw::Zlib::deflateStream::deflateParams{ my $self = shift ; my ($got) = ParseParameters(0, { 'Level' => [1, 1, Parse_signed, undef], 'Strategy' => [1, 1, Parse_unsigned, undef], 'Bufsize' => [1, 1, Parse_unsigned, undef], }, @_) ; croak "Compress::Raw::Zlib::deflateParams needs Level and/or Strategy" unless $got->parsed('Level') + $got->parsed('Strategy') + $got->parsed('Bufsize'); croak "Compress::Raw::Zlib::Inflate::deflateParams: Bufsize must be >= 1, you specified " . $got->value('Bufsize') if $got->parsed('Bufsize') && $got->value('Bufsize') <= 1; my $flags = 0; $flags |= 1 if $got->parsed('Level') ; $flags |= 2 if $got->parsed('Strategy') ; $flags |= 4 if $got->parsed('Bufsize') ; $self->_deflateParams($flags, $got->value('Level'), $got->value('Strategy'), $got->value('Bufsize'));}# Autoload methods go after __END__, and are processed by the autosplit program.1;__END__=head1 NAMECompress::Raw::Zlib - Low-Level Interface to zlib compression library=head1 SYNOPSIS use Compress::Raw::Zlib ; ($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ; $status = $d->deflate($input, $output) ; $status = $d->flush($output [, $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) = new Compress::Raw::Zlib::Inflate( [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(); $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 DESCRIPTIONThe I<Compress::Raw::Zlib> module provides a Perl interface to the I<zlib>compression library (see L</AUTHOR> for details about where to getI<zlib>). =head1 Compress::Raw::Zlib::DeflateThis 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) = new Compress::Raw::Zlib::Deflate( [OPT] ) >Initialises a deflation object. If you are familiar with the I<zlib> library, it combines thefeatures of the I<zlib> functions C<deflateInit>, C<deflateInit2>and C<deflateSetDictionary>.If successful, it will return the initialised deflation object, C<$d>and a C<$status> of C<Z_OK> in a list context. In scalar context itreturns the deflation object, C<$d>, only.If not successful, the returned deflation object, C<$d>, will beI<undef> and C<$status> will hold the a 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.Below 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>For a definition of the meaning and valid values for C<WindowBits>refer to 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>, C<Z_RLE>, C<Z_FIXED> andC<Z_HUFFMAN_ONLY>.The default is Z_DEFAULT_STRATEGY.=item B<-Dictionary>When a dictionary is specified I<Compress::Raw::Zlib> will automaticallycall C<deflateSetDictionary> directly after calling C<deflateInit>. TheAdler32 value for the dictionary can be obtained by calling the method C<$d-E<gt>dict_adler()>.The default is no dictionary.=item B<-Bufsize>Sets the initial size for the output buffer used by the C<$d-E<gt>deflate>and C<$d-E<gt>flush> methods. If the buffer has to bereallocated to increase the size, it will grow in increments ofC<Bufsize>.The default buffer size is 4096.=item B<-AppendOutput>This option controls how data is written to the output buffer by theC<$d-E<gt>deflate> and C<$d-E<gt>flush> methods.If the C<AppendOutput> option is set to false, the output buffers in theC<$d-E<gt>deflate> and C<$d-E<gt>flush> methods will be truncated beforeuncompressed data is written to them.If the option is set to true, uncompressed data will be appended to theoutput buffer in the C<$d-E<gt>deflate> and C<$d-E<gt>flush> methods.This option defaults to false.=item B<-CRC32>If set to true, a crc32 checksum of the uncompressed data will becalculated. Use the C<$d-E<gt>crc32> method to retrieve this value.This option defaults to false.=item B<-ADLER32>If set to true, an adler32 checksum of the uncompressed data will becalculated. Use the C<$d-E<gt>adler32> method to retrieve this value.This option defaults to false.=backHere is an example of using the C<Compress::Raw::Zlib::Deflate> optionalparameter list to override the default buffer size and compressionlevel. All other options will take their default values. my $d = new Compress::Raw::Zlib::Deflate ( -Bufsize => 300, -Level => Z_BEST_SPEED ) ;=head2 B<$status = $d-E<gt>deflate($input, $output)>Deflates the contents of C<$input> and writes the compressed data toC<$output>.The C<$input> and C<$output> parameters can be either scalars or scalarreferences.When finished, C<$input> will be completely processed (assuming therewere no errors). If the deflation was successful it writes the deflateddata to C<$output> and returns a status value of C<Z_OK>.On error, it returns a I<zlib> error code.If the C<AppendOutput> option is set to true in the constructor forthe C<$d> object, the compressed data will be appended to C<$output>. Ifit is false, C<$output> will be truncated before any compressed data iswritten to it.B<Note>: This method will not necessarily write compressed data toC<$output> every time it is called. So do not assume that there has beenan error if the contents of C<$output> is empty on returning fromthis method. As long as the return code from the method is C<Z_OK>,the deflate has succeeded.=head2 B<$status = $d-E<gt>flush($output [, $flush_type]) >Typically used to finish the deflation. Any pending output will bewritten to C<$output>.Returns C<Z_OK> if successful.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.If the C<AppendOutput> option is set to true in the constructor forthe C<$d> object, the compressed data will be appended to C<$output>. Ifit is false, C<$output> will be truncated before any compressed data iswritten to it.=head2 B<$status = $d-E<gt>deflateParams([OPT])>Change settings for the deflate object 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>. =item B<-BufSize>Sets the initial size for the output buffer used by the C<$d-E<gt>deflate>and C<$d-E<gt>flush> methods. If the buffer has to bereallocated to increase the size, it will grow in increments ofC<Bufsize>.=back=head2 B<$status = $d-E<gt>deflateTune($good_length, $max_lazy, $nice_length, $max_chain)>Tune the internal settings for the deflate object C<$d>. This option isonly available if you are running zlib 1.2.2.3 or better.Refer to the documentation in zlib.h for instructions on how to flyC<deflateTune>.=head2 B<$d-E<gt>dict_adler()>Returns the adler32 value for the dictionary.=head2 B<$d-E<gt>crc32()>Returns the crc32 value for the uncompressed data to date. If the C<CRC32> option is not enabled in the constructor for this object,this method will always return 0;=head2 B<$d-E<gt>adler32()>Returns the adler32 value for the uncompressed data to date.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -