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

📄 io::compress::gzip.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 3 页
字号:
.Ve.PPTo read from an existing Perl filehandle, \f(CW$input\fR, and write thecompressed data to a buffer, \f(CW$buffer\fR..PP.Vb 4\&    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 \*(Aqfile1.txt\*(Aq: $!\en" ;\&    my $buffer ;\&    gzip $input => \e$buffer \&        or die "gzip failed: $GzipError\en";.Ve.PPTo compress all files in the directory \*(L"/my/home\*(R" that match \*(L"*.txt\*(R"and store the compressed data in the same directory.PP.Vb 3\&    use strict ;\&    use warnings ;\&    use IO::Compress::Gzip qw(gzip $GzipError) ;\&\&    gzip \*(Aq</my/home/*.txt>\*(Aq => \*(Aq<*.gz>\*(Aq\&        or die "gzip failed: $GzipError\en";.Ve.PPand if you want to compress each file one at a time, this will do the trick.PP.Vb 3\&    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 \*(Aq$input\*(Aq: $GzipError\en";\&    }.Ve.SH "OO Interface".IX Header "OO Interface".Sh "Constructor".IX Subsection "Constructor"The format of the constructor for \f(CW\*(C`IO::Compress::Gzip\*(C'\fR is shown below.PP.Vb 2\&    my $z = new IO::Compress::Gzip $output [,OPTS]\&        or die "IO::Compress::Gzip failed: $GzipError\en";.Ve.PPIt returns an \f(CW\*(C`IO::Compress::Gzip\*(C'\fR object on success and undef on failure. The variable \f(CW$GzipError\fR will contain an error message on failure..PPIf you are running Perl 5.005 or better the object, \f(CW$z\fR, returned from IO::Compress::Gzip can be used exactly like an IO::File filehandle. This means that all normal output file operations can be carried out with \f(CW$z\fR. For example, to write to a compressed file/buffer you can use either of these forms.PP.Vb 2\&    $z\->print("hello world\en");\&    print $z "hello world\en";.Ve.PPThe mandatory parameter \f(CW$output\fR is used to control the destinationof the compressed data. This parameter can take one of these forms..IP "A filename" 5.IX Item "A filename"If the \f(CW$output\fR 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..IP "A filehandle" 5.IX Item "A filehandle"If the \f(CW$output\fR parameter is a filehandle, the compressed data will bewritten to it.The string '\-' can be used as an alias for standard output..IP "A scalar reference" 5.IX Item "A scalar reference"If \f(CW$output\fR is a scalar reference, the compressed data will be storedin \f(CW$$output\fR..PPIf the \f(CW$output\fR parameter is any other type, \f(CW\*(C`IO::Compress::Gzip\*(C'\fR::new willreturn undef..Sh "Constructor Options".IX Subsection "Constructor Options"\&\f(CW\*(C`OPTS\*(C'\fR is any combination of the following options:.ie n .IP """AutoClose => 0|1""" 5.el .IP "\f(CWAutoClose => 0|1\fR" 5.IX Item "AutoClose => 0|1"This option is only valid when the \f(CW$output\fR parameter is a filehandle. Ifspecified, and the value is true, it will result in the \f(CW$output\fR beingclosed once either the \f(CW\*(C`close\*(C'\fR method is called or the \f(CW\*(C`IO::Compress::Gzip\*(C'\fRobject is destroyed..SpThis parameter defaults to 0..ie n .IP """Append => 0|1""" 5.el .IP "\f(CWAppend => 0|1\fR" 5.IX Item "Append => 0|1"Opens \f(CW$output\fR in append mode..SpThe behaviour of this option is dependent on the type of \f(CW$output\fR..RS 5.IP "\(bu" 5A Buffer.SpIf \f(CW$output\fR is a buffer and \f(CW\*(C`Append\*(C'\fR is enabled, all compressed datawill be append to the end if \f(CW$output\fR. Otherwise \f(CW$output\fR will becleared before any data is written to it..IP "\(bu" 5A Filename.SpIf \f(CW$output\fR is a filename and \f(CW\*(C`Append\*(C'\fR 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..IP "\(bu" 5A Filehandle.SpIf \f(CW$output\fR is a filehandle, the file pointer will be positioned to theend of the file via a call to \f(CW\*(C`seek\*(C'\fR before any compressed data is writtento it.  Otherwise the file pointer will not be moved..RE.RS 5.SpThis parameter defaults to 0..RE.ie n .IP """Merge => 0|1""" 5.el .IP "\f(CWMerge => 0|1\fR" 5.IX Item "Merge => 0|1"This option is used to compress input data and append it to an existingcompressed data stream in \f(CW$output\fR. The end result is a single compresseddata stream stored in \f(CW$output\fR..SpIt is a fatal error to attempt to use this option when \f(CW$output\fR is not an\&\s-1RFC\s0 1952 data stream..SpThere are a number of other limitations with the \f(CW\*(C`Merge\*(C'\fR option:.RS 5.IP "1." 5This module needs to have been built with zlib 1.2.1 or better to work. Afatal error will be thrown if \f(CW\*(C`Merge\*(C'\fR is used with an older version ofzlib..IP "2." 5If \f(CW$output\fR is a file or a filehandle, it must be seekable..RE.RS 5.SpThis parameter defaults to 0..RE.IP "\-Level" 5.IX 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..Sp.Vb 4\&   Z_NO_COMPRESSION\&   Z_BEST_SPEED\&   Z_BEST_COMPRESSION\&   Z_DEFAULT_COMPRESSION.Ve.SpThe default is Z_DEFAULT_COMPRESSION..SpNote, these constants are not imported by \f(CW\*(C`IO::Compress::Gzip\*(C'\fR by default..Sp.Vb 3\&    use IO::Compress::Gzip qw(:strategy);\&    use IO::Compress::Gzip qw(:constants);\&    use IO::Compress::Gzip qw(:all);.Ve.IP "\-Strategy" 5.IX Item "-Strategy"Defines the strategy used to tune the compression. Use one of the symbolicconstants defined below..Sp.Vb 5\&   Z_FILTERED\&   Z_HUFFMAN_ONLY\&   Z_RLE\&   Z_FIXED\&   Z_DEFAULT_STRATEGY.Ve.SpThe default is Z_DEFAULT_STRATEGY..ie n .IP """Minimal => 0|1""" 5.el .IP "\f(CWMinimal => 0|1\fR" 5.IX Item "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 in\&\s-1RFC\s0 1952..SpSee the section titled \*(L"Compliance\*(R" in \s-1RFC\s0 1952 for a definition of the values used for the fields in the gzip header..SpAll other parameters that control the content of the gzip header willbe ignored if this parameter is set to 1..SpThis parameter defaults to 0..ie n .IP """Comment => $comment""" 5.el .IP "\f(CWComment => $comment\fR" 5.IX Item "Comment => $comment"Stores the contents of \f(CW$comment\fR in the \s-1COMMENT\s0 field inthe gzip header.By default, no comment field is written to the gzip file..SpIf the \f(CW\*(C`\-Strict\*(C'\fR option is enabled, the comment can only consist of \s-1ISO\s08859\-1 characters plus line feed..SpIf the \f(CW\*(C`\-Strict\*(C'\fR option is disabled, the comment field can contain anycharacter except \s-1NULL\s0. If any null characters are present, the fieldwill be truncated at the first \s-1NULL\s0..ie n .IP """Name => $string""" 5.el .IP "\f(CWName => $string\fR" 5.IX Item "Name => $string"Stores the contents of \f(CW$string\fR in the gzip \s-1NAME\s0 header field. If\&\f(CW\*(C`Name\*(C'\fR is not specified, no gzip \s-1NAME\s0 field will be created..SpIf the \f(CW\*(C`\-Strict\*(C'\fR option is enabled, \f(CW$string\fR can only consist of \s-1ISO\s08859\-1 characters..SpIf \f(CW\*(C`\-Strict\*(C'\fR is disabled, then \f(CW$string\fR can contain any characterexcept \s-1NULL\s0. If any null characters are present, the field will betruncated at the first \s-1NULL\s0..ie n .IP """Time => $number""" 5.el .IP "\f(CWTime => $number\fR" 5.IX Item "Time => $number"Sets the \s-1MTIME\s0 field in the gzip header to \f(CW$number\fR..SpThis field defaults to the time the \f(CW\*(C`IO::Compress::Gzip\*(C'\fR object was createdif this option is not specified..ie n .IP """TextFlag => 0|1""" 5.el .IP "\f(CWTextFlag => 0|1\fR" 5.IX Item "TextFlag => 0|1"This parameter controls the setting of the \s-1FLG\s0.FTEXT bit in the gzipheader. It is used to signal that the data stored in the gzip file/bufferis probably text..SpThe default is 0..ie n .IP """HeaderCRC => 0|1""" 5.el .IP "\f(CWHeaderCRC => 0|1\fR" 5.IX Item "HeaderCRC => 0|1"When true this parameter will set the \s-1FLG\s0.FHCRC bit to 1 in the gzip headerand set the \s-1CRC16\s0 header field to the \s-1CRC\s0 of the complete gzip headerexcept the \s-1CRC16\s0 field itself..Sp\&\fBNote\fR that gzip files created with the \f(CW\*(C`HeaderCRC\*(C'\fR 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..SpThis parameter defaults to 0..ie n .IP """OS_Code => $value""" 5.el .IP "\f(CWOS_Code => $value\fR" 5.IX Item "OS_Code => $value"Stores \f(CW$value\fR in the gzip \s-1OS\s0 header field. A number between 0 and 255 isvalid..SpIf not specified, this parameter defaults to the \s-1OS\s0 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..ie n .IP """ExtraField => $data""" 5.el .IP "\f(CWExtraField => $data\fR" 5.IX Item "ExtraField => $data"This parameter allows additional metadata to be stored in the ExtraField inthe gzip header. An \s-1RFC\s0 1952 compliant ExtraField consists of zero or moresubfields. Each subfield consists of a two byte header followed by thesubfield data..SpThe list of subfields can be supplied in any of the following formats.Sp.Vb 12\&    \-ExtraField => [$id1, $data1,\&                    $id2, $data2,\&                     ...\&                   ]\&    \-ExtraField => [ [$id1 => $data1],\&                     [$id2 => $data2],\&                     ...\&                   ]\&    \-ExtraField => { $id1 => $data1,\&                     $id2 => $data2,\&                     ...\&                   }.Ve.SpWhere \f(CW$id1\fR, \f(CW$id2\fR are two byte subfield \s-1ID\s0's. The second byte ofthe \s-1ID\s0 cannot be 0, unless the \f(CW\*(C`Strict\*(C'\fR option has been disabled..SpIf you use the hash syntax, you have no control over the order in whichthe ExtraSubFields are stored, plus you cannot have SubFields withduplicate \s-1ID\s0..SpAlternatively the list of subfields can by supplied as a scalar, thus.Sp.Vb 1\&    \-ExtraField => $rawdata.Ve.SpIf you use the raw format, and the \f(CW\*(C`Strict\*(C'\fR option is enabled,\&\f(CW\*(C`IO::Compress::Gzip\*(C'\fR will check that \f(CW$rawdata\fR consists of zero or moreconformant sub-fields. When \f(CW\*(C`Strict\*(C'\fR is disabled, \f(CW$rawdata\fR canconsist of any arbitrary byte stream..SpThe maximum size of the Extra Field 65535 bytes..ie n .IP """ExtraFlags => $value""" 5.el .IP "\f(CWExtraFlags => $value\fR" 5.IX Item "ExtraFlags => $value"Sets the \s-1XFL\s0 byte in the gzip header to \f(CW$value\fR..SpIf this option is not present, the value stored in \s-1XFL\s0 field will bedetermined by the setting of the \f(CW\*(C`Level\*(C'\fR option..SpIf \f(CW\*(C`Level => Z_BEST_SPEED\*(C'\fR has been specified then \s-1XFL\s0 is set to 2.If \f(CW\*(C`Level => Z_BEST_COMPRESSION\*(C'\fR has been specified then \s-1XFL\s0 is set to 4.Otherwise \s-1XFL\s0 is set to 0..ie n .IP """Strict => 0|1""" 5.el .IP "\f(CWStrict => 0|1\fR" 5.IX Item "Strict => 0|1"\&\f(CW\*(C`Strict\*(C'\fR will optionally police the values supplied with other optionsto ensure they are compliant with \s-1RFC1952\s0..SpThis option is enabled by default..SpIf \f(CW\*(C`Strict\*(C'\fR is enabled the following behaviour will be policed:.RS 5.IP "\(bu" 5The value supplied with the \f(CW\*(C`Name\*(C'\fR option can only contain \s-1ISO\s0 8859\-1characters..IP "\(bu" 5The value supplied with the \f(CW\*(C`Comment\*(C'\fR option can only contain \s-1ISO\s0 8859\-1characters plus line-feed..IP "\(bu" 5The values supplied with the \f(CW\*(C`\-Name\*(C'\fR and \f(CW\*(C`\-Comment\*(C'\fR options cannotcontain multiple embedded nulls..IP "\(bu" 5

⌨️ 快捷键说明

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