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

📄 zip.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 3 页
字号:
        $bit <<= 1 ;    }    return IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_EXT_TIMESTAMP,                                                 pack("C", $flags) .  $times);}sub mkUnix2Extra{    my $ids = '';    for my $id (@_)    {        $ids .= pack("v", $id);    }    return IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_INFO_ZIP_UNIX2,                                                  $ids);}# from Archive::Zipsub _unixToDosTime    # Archive::Zip::Member{	my $time_t = shift;    # TODO - add something to cope with unix time < 1980 	my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime($time_t);	my $dt = 0;	$dt += ( $sec >> 1 );	$dt += ( $min << 5 );	$dt += ( $hour << 11 );	$dt += ( $mday << 16 );	$dt += ( ( $mon + 1 ) << 21 );	$dt += ( ( $year - 80 ) << 25 );	return $dt;}1;__END__=head1 NAMEIO::Compress::Zip - Write zip files/buffers  =head1 SYNOPSIS    use IO::Compress::Zip qw(zip $ZipError) ;    my $status = zip $input => $output [,OPTS]         or die "zip failed: $ZipError\n";    my $z = new IO::Compress::Zip $output [,OPTS]        or die "zip failed: $ZipError\n";    $z->print($string);    $z->printf($format, $string);    $z->write($string);    $z->syswrite($string [, $length, $offset]);    $z->flush();    $z->tell();    $z->eof();    $z->seek($position, $whence);    $z->binmode();    $z->fileno();    $z->opened();    $z->autoflush();    $z->input_line_number();    $z->newStream( [OPTS] );        $z->deflateParams();        $z->close() ;    $ZipError ;    # IO::File mode    print $z $string;    printf $z $format, $string;    tell $z    eof $z    seek $z, $position, $whence    binmode $z    fileno $z    close $z ;    =head1 DESCRIPTIONThis module provides a Perl interface that allows writing zip compressed data to files or buffer.The primary purpose of this module is to provide streaming write access tozip files and buffers. It is not a general-purpose file archiver. If thatis what you want, check out C<Archive::Zip>.At present three compression methods are supported by IO::Compress::Zip,namely Store (no compression at all), Deflate and Bzip2.Note that to create Bzip2 content, the module C<IO::Compress::Bzip2> mustbe installed.For reading zip files/buffers, see the companion module L<IO::Uncompress::Unzip|IO::Uncompress::Unzip>.=head1 Functional InterfaceA top-level function, C<zip>, is provided to carry out"one-shot" compression between buffers and/or files. For finercontrol over the compression process, see the L</"OO Interface">section.    use IO::Compress::Zip qw(zip $ZipError) ;    zip $input => $output [,OPTS]         or die "zip failed: $ZipError\n";The functional interface needs Perl5.005 or better.=head2 zip $input => $output [, OPTS]C<zip> expects at least two parameters, C<$input> and C<$output>.=head3 The C<$input> parameterThe parameter, C<$input>, is used to define the source ofthe uncompressed data. It can take one of the following forms:=over 5=item A filenameIf the C<$input> parameter is a simple scalar, it is assumed to be afilename. This file will be opened for reading and the input datawill be read from it.=item A filehandleIf the C<$input> parameter is a filehandle, the input data will beread from it.The string '-' can be used as an alias for standard input.=item A scalar reference If C<$input> is a scalar reference, the input data will be readfrom C<$$input>.=item An array reference If C<$input> is an array reference, each element in the array must be afilename.The input data will be read from each file in turn. The complete array will be walked to ensure that it onlycontains valid filenames before any data is compressed.=item An Input FileGlob stringIf C<$input> is a string that is delimited by the characters "<" and ">"C<zip> will assume that it is an I<input fileglob string>. Theinput is the list of files that match the fileglob.If the fileglob does not match any files ...See L<File::GlobMapper|File::GlobMapper> for more details.=backIf the C<$input> parameter is any other type, C<undef> will be returned.In addition, if C<$input> is a simple filename, the default values forthe C<Name>, C<Time>, C<ExtAttr> and C<exTime> options will be sourced from that file.If you do not want to use these defaults they can be overridden byexplicitly setting the C<Name>, C<Time>, C<ExtAttr> and C<exTime> options or by setting theC<Minimal> parameter.=head3 The C<$output> parameterThe parameter C<$output> is used to control the destination of thecompressed 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 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<zip> 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 each be storedin C<$output> as a distinct entry.=head2 Optional ParametersUnless specified below, the optional parameters for C<zip>,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<zip> 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<zip> 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.zip>.    use strict ;    use warnings ;    use IO::Compress::Zip qw(zip $ZipError) ;    my $input = "file1.txt";    zip $input => "$input.zip"        or die "zip failed: $ZipError\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::Zip qw(zip $ZipError) ;    use IO::File ;    my $input = new IO::File "<file1.txt"        or die "Cannot open 'file1.txt': $!\n" ;    my $buffer ;    zip $input => \$buffer         or die "zip failed: $ZipError\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::Zip qw(zip $ZipError) ;    zip '</my/home/*.txt>' => '<*.zip>'        or die "zip failed: $ZipError\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::Zip qw(zip $ZipError) ;    for my $input ( glob "/my/home/*.txt" )    {        my $output = "$input.zip" ;        zip $input => $output             or die "Error compressing '$input': $ZipError\n";    }=head1 OO Interface=head2 ConstructorThe format of the constructor for C<IO::Compress::Zip> is shown below    my $z = new IO::Compress::Zip $output [,OPTS]        or die "IO::Compress::Zip failed: $ZipError\n";It returns an C<IO::Compress::Zip> object on success and undef on failure. The variable C<$ZipError> will contain an error message on failure.If you are running Perl 5.005 or better the object, C<$z>, returned from IO::Compress::Zip 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::Zip>::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::Zip>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<< Name => $string >>Stores the contents of C<$string> in the zip filename header field. IfC<Name> is not specified, no zip filename field will be created.=item C<< Time => $number >>Sets the last modified time field in the zip header to $number.This field defaults to the time the C<IO::Compress::Zip> object was createdif this option is not specified.=item C<< ExtAttr => $attr >>This option controls the "external file attributes" field in the centralheader of the zip file. This is a 4 byte field.This option defaults to 0.=item C<< exTime => [$atime, $mtime, $ctime] >>This option expects an array reference with exactly three elements:C<$atime>, C<mtime> and C<$ctime>. These correspond to the last accesstime, last modification time and creation time respectively.It uses these values to set the extended timestamp field in the local zipheader to the three values, $atime, $mtime, $ctime and sets the extendedtimestamp field in the central zip header to C<$mtime>.If any of the three values is C<undef> that time value will not be used.So, for example, to set only the C<$mtime> you would use this    exTime => [undef, $mtime, undef]If the C<Minimal> option is set to true, this option will be ignored.By default no extended time field is created.=item C<< Comment => $comment >>Stores the contents of C<$comment> in the Central File Header ofthe zip file.By default, no comment field is written to the zip file.=item C<< ZipComment => $comment >>Stores the contents of C<$comment> in the End of Central Directory recordof the zip file.By default, no comment field is written to the zip file.=item C<< Method => $method >>Controls which compression method is used. At present three compressionmethods are supported, namely Store (no compression at all), Deflate andBzip2.The symbols, ZIP_CM_STORE, ZIP_CM_DEFLATE and ZIP_CM_BZIP2 are used toselect the compression method.These constants are not imported by C<IO::Compress::Zip> by default.    use IO::Compress::Zip qw(:zip_method);    use IO::Compress::Zip qw(:constants);    use IO::Compress::Zip qw(:all);Note that to create Bzip2 content, the module C<IO::Compress::Bzip2> mustbe installed. A fatal error will be thrown if you attempt to create Bzip2content when C<IO::Compress::Bzip2> is not available.

⌨️ 快捷键说明

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