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

📄 gzip.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 3 页
字号:
=over 5=item A filenameIf the C<$output> parameter is a simple scalar, it is assumed to be afilename.  This file will be opened for writing and the compresseddata will be written to it.=item A filehandleIf the C<$output> parameter is a filehandle, the compressed datawill 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 bestored in C<$$output>.=item An Array ReferenceIf C<$output> is an array reference, the compressed data will bepushed onto the array.=item An Output FileGlobIf C<$output> is a string that is delimited by the characters "<" and ">"C<gzip> will assume that it is an I<output fileglob string>. Theoutput is the list of files that match the fileglob.When C<$output> is an fileglob string, C<$input> must also be a fileglobstring. Anything else is an error.=backIf the C<$output> parameter is any other type, C<undef> will be returned.=head2 NotesWhen C<$input> maps to multiple files/buffers and C<$output> is a singlefile/buffer the input files/buffers will be storedin C<$output> as a concatenated series of compressed data streams.=head2 Optional ParametersUnless specified below, the optional parameters for C<gzip>,C<OPTS>, are the same as those used with the OO interface defined in theL</"Constructor Options"> section below.=over 5=item C<< AutoClose => 0|1 >>This option applies to any input or output data streams to C<gzip> that are filehandles.If C<AutoClose> is specified, and the value is true, it will result in allinput and/or output filehandles being closed once C<gzip> hascompleted.This parameter defaults to 0.=item C<< BinModeIn => 0|1 >>When reading from a file or filehandle, set C<binmode> before reading.Defaults to 0.=item C<< Append => 0|1 >>TODO=back=head2 ExamplesTo read the contents of the file C<file1.txt> and write the compresseddata to the file C<file1.txt.gz>.    use strict ;    use warnings ;    use IO::Compress::Gzip qw(gzip $GzipError) ;    my $input = "file1.txt";    gzip $input => "$input.gz"        or die "gzip failed: $GzipError\n";To read from an existing Perl filehandle, C<$input>, and write thecompressed data to a buffer, C<$buffer>.    use strict ;    use warnings ;    use IO::Compress::Gzip qw(gzip $GzipError) ;    use IO::File ;    my $input = new IO::File "<file1.txt"        or die "Cannot open 'file1.txt': $!\n" ;    my $buffer ;    gzip $input => \$buffer         or die "gzip failed: $GzipError\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::Gzip qw(gzip $GzipError) ;    gzip '</my/home/*.txt>' => '<*.gz>'        or die "gzip failed: $GzipError\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::Gzip qw(gzip $GzipError) ;    for my $input ( glob "/my/home/*.txt" )    {        my $output = "$input.gz" ;        gzip $input => $output             or die "Error compressing '$input': $GzipError\n";    }=head1 OO Interface=head2 ConstructorThe format of the constructor for C<IO::Compress::Gzip> is shown below    my $z = new IO::Compress::Gzip $output [,OPTS]        or die "IO::Compress::Gzip failed: $GzipError\n";It returns an C<IO::Compress::Gzip> object on success and undef on failure. The variable C<$GzipError> will contain an error message on failure.If you are running Perl 5.005 or better the object, C<$z>, returned from IO::Compress::Gzip can be used exactly like an L<IO::File|IO::File> 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 destinationof the compressed data. This parameter can take one of these forms.=over 5=item A filenameIf the C<$output> parameter is a simple scalar, it is assumed to be afilename. This file will be opened for writing and the compressed datawill be written to it.=item A filehandleIf the C<$output> parameter is a filehandle, the compressed data will bewritten 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 storedin C<$$output>.=backIf the C<$output> parameter is any other type, C<IO::Compress::Gzip>::new willreturn undef.=head2 Constructor OptionsC<OPTS> 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. Ifspecified, and the value is true, it will result in the C<$output> beingclosed once either the C<close> method is called or the C<IO::Compress::Gzip>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 BufferIf C<$output> is a buffer and C<Append> is enabled, all compressed datawill be append to the end if C<$output>. Otherwise C<$output> will becleared before any data is written to it.=item * A FilenameIf C<$output> is a filename and C<Append> is enabled, the file will beopened in append mode. Otherwise the contents of the file, if any, will betruncated before any compressed data is written to it.=item * A FilehandleIf C<$output> is a filehandle, the file pointer will be positioned to theend of the file via a call to C<seek> before any compressed data is writtento it.  Otherwise the file pointer will not be moved.=backThis parameter defaults to 0.=item C<< Merge => 0|1 >>This option is used to compress input data and append it to an existingcompressed data stream in C<$output>. The end result is a single compresseddata stream stored in C<$output>. It is a fatal error to attempt to use this option when C<$output> is not anRFC 1952 data stream.There are a number of other limitations with the C<Merge> option:=over 5 =item 1This module needs to have been built with zlib 1.2.1 or better to work. Afatal error will be thrown if C<Merge> is used with an older version ofzlib.  =item 2If C<$output> is a file or a filehandle, it must be seekable.=backThis parameter defaults to 0.=item -Level Defines the compression level used by zlib. The value should either bea number between 0 and 9 (0 means no compression and 9 is maximumcompression), or one of the symbolic constants defined below.   Z_NO_COMPRESSION   Z_BEST_SPEED   Z_BEST_COMPRESSION   Z_DEFAULT_COMPRESSIONThe default is Z_DEFAULT_COMPRESSION.Note, these constants are not imported by C<IO::Compress::Gzip> by default.    use IO::Compress::Gzip qw(:strategy);    use IO::Compress::Gzip qw(:constants);    use IO::Compress::Gzip qw(:all);=item -Strategy Defines the strategy used to tune the compression. Use one of the symbolicconstants defined below.   Z_FILTERED   Z_HUFFMAN_ONLY   Z_RLE   Z_FIXED   Z_DEFAULT_STRATEGYThe default is Z_DEFAULT_STRATEGY.=item C<< Minimal => 0|1 >>If specified, this option will force the creation of the smallest possiblecompliant gzip header (which is exactly 10 bytes long) as defined inRFC 1952.See the section titled "Compliance" in RFC 1952 for a definition of the values used for the fields in the gzip header.All other parameters that control the content of the gzip header willbe ignored if this parameter is set to 1.This parameter defaults to 0.=item C<< Comment => $comment >>Stores the contents of C<$comment> in the COMMENT field inthe gzip header.By default, no comment field is written to the gzip file.If the C<-Strict> option is enabled, the comment can only consist of ISO8859-1 characters plus line feed.If the C<-Strict> option is disabled, the comment field can contain anycharacter except NULL. If any null characters are present, the fieldwill be truncated at the first NULL.=item C<< Name => $string >>Stores the contents of C<$string> in the gzip NAME header field. IfC<Name> is not specified, no gzip NAME field will be created.If the C<-Strict> option is enabled, C<$string> can only consist of ISO8859-1 characters.If C<-Strict> is disabled, then C<$string> can contain any characterexcept NULL. If any null characters are present, the field will betruncated at the first NULL.=item C<< Time => $number >>Sets the MTIME field in the gzip header to $number.This field defaults to the time the C<IO::Compress::Gzip> object was createdif this option is not specified.=item C<< TextFlag => 0|1 >>This parameter controls the setting of the FLG.FTEXT bit in the gzipheader. It is used to signal that the data stored in the gzip file/bufferis probably text.The default is 0. =item C<< HeaderCRC => 0|1 >>When true this parameter will set the FLG.FHCRC bit to 1 in the gzip headerand set the CRC16 header field to the CRC of the complete gzip headerexcept the CRC16 field itself.B<Note> that gzip files created with the C<HeaderCRC> flag set to 1 cannotbe read by most, if not all, of the the standard gunzip utilities, mostnotably gzip version 1.2.4. You should therefore avoid using this option ifyou want to maximize the portability of your gzip files.This parameter defaults to 0.=item C<< OS_Code => $value >>Stores C<$value> in the gzip OS header field. A number between 0 and 255 isvalid.If not specified, this parameter defaults to the OS code of the OperatingSystem this module was built on. The value 3 is used as a catch-all for allUnix variants and unknown Operating Systems.=item C<< ExtraField => $data >>This parameter allows additional metadata to be stored in the ExtraField inthe gzip header. An RFC 1952 compliant ExtraField consists of zero or moresubfields. Each subfield consists of a two byte header followed by thesubfield data.The list of subfields can be supplied in any of the following formats    -ExtraField => [$id1, $data1,                    $id2, $data2,                     ...                   ]    -ExtraField => [ [$id1 => $data1],                     [$id2 => $data2],                     ...                   ]    -ExtraField => { $id1 => $data1,                     $id2 => $data2,                     ...                   }Where C<$id1>, C<$id2> are two byte subfield ID's. The second byte ofthe ID cannot be 0, unless the C<Strict> option has been disabled.If you use the hash syntax, you have no control over the order in whichthe ExtraSubFields are stored, plus you cannot have SubFields withduplicate ID.Alternatively the list of subfields can by supplied as a scalar, thus    -ExtraField => $rawdataIf you use the raw format, and the C<Strict> option is enabled,C<IO::Compress::Gzip> will check that C<$rawdata> consists of zero or moreconformant sub-fields. When C<Strict> is disabled, C<$rawdata> canconsist of any arbitrary byte stream.The maximum size of the Extra Field 65535 bytes.=item C<< ExtraFlags => $value >>Sets the XFL byte in the gzip header to C<$value>.If this option is not present, the value stored in XFL field will bedetermined by the setting of the C<Level> option.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -