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

📄 gzip.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 3 页
字号:
package IO::Compress::Gzip ;require 5.004 ;use strict ;use warnings;use bytes;use IO::Compress::RawDeflate 2.008 ;use Compress::Raw::Zlib  2.008 ;use IO::Compress::Base::Common  2.008 qw(:Status :Parse createSelfTiedObject);use IO::Compress::Gzip::Constants 2.008 ;use IO::Compress::Zlib::Extra 2.008 ;BEGIN{    if (defined &utf8::downgrade )       { *noUTF8 = \&utf8::downgrade }    else      { *noUTF8 = sub {} }  }require Exporter ;our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $GzipError);$VERSION = '2.008';$GzipError = '' ;@ISA    = qw(Exporter IO::Compress::RawDeflate);@EXPORT_OK = qw( $GzipError gzip ) ;%EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ;push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;Exporter::export_ok_tags('all');sub new{    my $class = shift ;    my $obj = createSelfTiedObject($class, \$GzipError);    $obj->_create(undef, @_);}sub gzip{    my $obj = createSelfTiedObject(undef, \$GzipError);    return $obj->_def(@_);}#sub newHeader#{#    my $self = shift ;#    #return GZIP_MINIMUM_HEADER ;#    return $self->mkHeader(*$self->{Got});#}sub getExtraParams{    my $self = shift ;    return (            # zlib behaviour            $self->getZlibParams(),            # Gzip header fields            'Minimal'   => [0, 1, Parse_boolean,   0],            'Comment'   => [0, 1, Parse_any,       undef],            'Name'      => [0, 1, Parse_any,       undef],            'Time'      => [0, 1, Parse_any,       undef],            'TextFlag'  => [0, 1, Parse_boolean,   0],            'HeaderCRC' => [0, 1, Parse_boolean,   0],            'OS_Code'   => [0, 1, Parse_unsigned,  $Compress::Raw::Zlib::gzip_os_code],            'ExtraField'=> [0, 1, Parse_any,       undef],            'ExtraFlags'=> [0, 1, Parse_any,       undef],        );}sub ckParams{    my $self = shift ;    my $got = shift ;    # gzip always needs crc32    $got->value('CRC32' => 1);    return 1        if $got->value('Merge') ;    my $strict = $got->value('Strict') ;    {        if (! $got->parsed('Time') ) {            # Modification time defaults to now.            $got->value('Time' => time) ;        }        # Check that the Name & Comment don't have embedded NULLs        # Also check that they only contain ISO 8859-1 chars.        if ($got->parsed('Name') && defined $got->value('Name')) {            my $name = $got->value('Name');                            return $self->saveErrorString(undef, "Null Character found in Name",                                                Z_DATA_ERROR)                if $strict && $name =~ /\x00/ ;            return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Name",                                                Z_DATA_ERROR)                if $strict && $name =~ /$GZIP_FNAME_INVALID_CHAR_RE/o ;        }        if ($got->parsed('Comment') && defined $got->value('Comment')) {            my $comment = $got->value('Comment');            return $self->saveErrorString(undef, "Null Character found in Comment",                                                Z_DATA_ERROR)                if $strict && $comment =~ /\x00/ ;            return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Comment",                                                Z_DATA_ERROR)                if $strict && $comment =~ /$GZIP_FCOMMENT_INVALID_CHAR_RE/o;        }        if ($got->parsed('OS_Code') ) {            my $value = $got->value('OS_Code');            return $self->saveErrorString(undef, "OS_Code must be between 0 and 255, got '$value'")                if $value < 0 || $value > 255 ;                    }        # gzip only supports Deflate at present        $got->value('Method' => Z_DEFLATED) ;        if ( ! $got->parsed('ExtraFlags')) {            $got->value('ExtraFlags' => 2)                 if $got->value('Level') == Z_BEST_SPEED ;            $got->value('ExtraFlags' => 4)                 if $got->value('Level') == Z_BEST_COMPRESSION ;        }        my $data = $got->value('ExtraField') ;        if (defined $data) {            my $bad = IO::Compress::Zlib::Extra::parseExtraField($data, $strict, 1) ;            return $self->saveErrorString(undef, "Error with ExtraField Parameter: $bad", Z_DATA_ERROR)                if $bad ;            $got->value('ExtraField', $data) ;        }    }    return 1;}sub mkTrailer{    my $self = shift ;    return pack("V V", *$self->{Compress}->crc32(),                        *$self->{UnCompSize}->get32bit());}sub getInverseClass{    return ('IO::Uncompress::Gunzip',                \$IO::Uncompress::Gunzip::GunzipError);}sub getFileInfo{    my $self = shift ;    my $params = shift;    my $filename = shift ;    my $defaultTime = (stat($filename))[9] ;    $params->value('Name' => $filename)        if ! $params->parsed('Name') ;    $params->value('Time' => $defaultTime)         if ! $params->parsed('Time') ;}sub mkHeader{    my $self = shift ;    my $param = shift ;    # stort-circuit if a minimal header is requested.    return GZIP_MINIMUM_HEADER if $param->value('Minimal') ;    # METHOD    my $method = $param->valueOrDefault('Method', GZIP_CM_DEFLATED) ;    # FLAGS    my $flags       = GZIP_FLG_DEFAULT ;    $flags |= GZIP_FLG_FTEXT    if $param->value('TextFlag') ;    $flags |= GZIP_FLG_FHCRC    if $param->value('HeaderCRC') ;    $flags |= GZIP_FLG_FEXTRA   if $param->wantValue('ExtraField') ;    $flags |= GZIP_FLG_FNAME    if $param->wantValue('Name') ;    $flags |= GZIP_FLG_FCOMMENT if $param->wantValue('Comment') ;        # MTIME    my $time = $param->valueOrDefault('Time', GZIP_MTIME_DEFAULT) ;    # EXTRA FLAGS    my $extra_flags = $param->valueOrDefault('ExtraFlags', GZIP_XFL_DEFAULT);    # OS CODE    my $os_code = $param->valueOrDefault('OS_Code', GZIP_OS_DEFAULT) ;    my $out = pack("C4 V C C",             GZIP_ID1,   # ID1            GZIP_ID2,   # ID2            $method,    # Compression Method            $flags,     # Flags            $time,      # Modification Time            $extra_flags, # Extra Flags            $os_code,   # Operating System Code            ) ;    # EXTRA    if ($flags & GZIP_FLG_FEXTRA) {        my $extra = $param->value('ExtraField') ;        $out .= pack("v", length $extra) . $extra ;    }    # NAME    if ($flags & GZIP_FLG_FNAME) {        my $name .= $param->value('Name') ;        $name =~ s/\x00.*$//;        $out .= $name ;        # Terminate the filename with NULL unless it already is        $out .= GZIP_NULL_BYTE             if !length $name or               substr($name, 1, -1) ne GZIP_NULL_BYTE ;    }    # COMMENT    if ($flags & GZIP_FLG_FCOMMENT) {        my $comment .= $param->value('Comment') ;        $comment =~ s/\x00.*$//;        $out .= $comment ;        # Terminate the comment with NULL unless it already is        $out .= GZIP_NULL_BYTE            if ! length $comment or               substr($comment, 1, -1) ne GZIP_NULL_BYTE;    }    # HEADER CRC    $out .= pack("v", crc32($out) & 0x00FF ) if $param->value('HeaderCRC') ;    noUTF8($out);    return $out ;}sub mkFinalTrailer{    return '';}1; __END__=head1 NAMEIO::Compress::Gzip - Write RFC 1952 files/buffers  =head1 SYNOPSIS    use IO::Compress::Gzip qw(gzip $GzipError) ;    my $status = gzip $input => $output [,OPTS]         or die "gzip failed: $GzipError\n";    my $z = new IO::Compress::Gzip $output [,OPTS]        or die "gzip failed: $GzipError\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() ;    $GzipError ;    # 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 compresseddata to files or buffer as defined in RFC 1952.All the gzip headers defined in RFC 1952 can be created usingthis module.For reading RFC 1952 files/buffers, see the companion module L<IO::Uncompress::Gunzip|IO::Uncompress::Gunzip>.=head1 Functional InterfaceA top-level function, C<gzip>, 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::Gzip qw(gzip $GzipError) ;    gzip $input => $output [,OPTS]         or die "gzip failed: $GzipError\n";The functional interface needs Perl5.005 or better.=head2 gzip $input => $output [, OPTS]C<gzip> 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<gzip> 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> and C<Time> 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> and C<Time> 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.

⌨️ 快捷键说明

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