X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FCompress%2FZlib%2FZlib.pm;h=f6e48ace8047d714e4af597cc21d8e25695d89cd;hb=667342e9372792655bd9e69275759a3f66394d54;hp=2b8777eb645ef9fd4fe1fba56741097f9f18ee0a;hpb=213b85e91648ac31188f8d8372c1f158e541c791;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Compress/Zlib/Zlib.pm b/ext/Compress/Zlib/Zlib.pm index 2b8777e..f6e48ac 100644 --- a/ext/Compress/Zlib/Zlib.pm +++ b/ext/Compress/Zlib/Zlib.pm @@ -1,7 +1,7 @@ # File : Zlib.pm # Author : Paul Marquess -# Created : 30 January 2005 -# Version : 1.34 +# Created : 23 September 2005 +# Version : 1.40 # # Copyright (c) 1995-2005 Paul Marquess. All rights reserved. # This program is free software; you can redistribute it and/or @@ -12,19 +12,18 @@ package Compress::Zlib; require 5.004 ; require Exporter; -require DynaLoader; use AutoLoader; use Carp ; use IO::Handle ; use strict ; -local ($^W) = 1; #use warnings ; -use vars qw($VERSION @ISA @EXPORT $AUTOLOAD); -use vars qw($deflateDefault $deflateParamsDefault $inflateDefault); +use warnings ; +our ($VERSION, @ISA, @EXPORT, $AUTOLOAD); +our ($deflateDefault, $deflateParamsDefault, $inflateDefault); -$VERSION = "1.34_01" ; +$VERSION = "1.40" ; -@ISA = qw(Exporter DynaLoader); +@ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @@ -44,6 +43,7 @@ $VERSION = "1.34_01" ; crc32 ZLIB_VERSION + ZLIB_VERNUM DEF_WBITS OS_CODE @@ -91,7 +91,14 @@ sub AUTOLOAD { goto &{$AUTOLOAD}; } -bootstrap Compress::Zlib $VERSION ; +eval { + require XSLoader; + XSLoader::load('Compress::Zlib', $VERSION); +} or do { + require DynaLoader; + local @ISA = qw(DynaLoader); + bootstrap Compress::Zlib $VERSION ; +} ; # Preloaded methods go here. @@ -197,7 +204,7 @@ $inflateDefault = { sub deflateInit(@) { my ($got) = ParseParameters($deflateDefault, @_) ; - local ($^W) = 0; #no warnings; + no warnings; croak "deflateInit: Bufsize must be >= 1, you specified $got->{Bufsize}" unless $got->{Bufsize} >= 1; _deflateInit($got->{Level}, $got->{Method}, $got->{WindowBits}, @@ -209,7 +216,7 @@ sub deflateInit(@) sub inflateInit(@) { my ($got) = ParseParameters($inflateDefault, @_) ; - local ($^W) = 0; #no warnings; + no warnings; croak "inflateInit: Bufsize must be >= 1, you specified $got->{Bufsize}" unless $got->{Bufsize} >= 1; _inflateInit($got->{WindowBits}, $got->{Bufsize}, $got->{Dictionary}); @@ -222,7 +229,7 @@ sub Compress::Zlib::deflateStream::deflateParams my ($got) = ParseParameters($deflateParamsDefault, @_) ; croak "deflateParams needs Level and/or Strategy" unless defined $got->{Level} || defined $got->{Strategy}; - local ($^W) = 0; #no warnings; + no warnings; croak "deflateParams: Bufsize must be >= 1, you specified $got->{Bufsize}" unless !defined $got->{Bufsize} || $got->{Bufsize} >= 1; @@ -442,7 +449,6 @@ sub memGunzip($) 1; __END__ -=cut =head1 NAME @@ -855,8 +861,11 @@ Here is an example of using B. =head1 COMPRESS/UNCOMPRESS Two high-level functions are provided by I to perform in-memory -compression. They are B and B. Two Perl subs are -provided which provide similar functionality. +compression/uncompression of RFC1950 data streams. They are called +B and B. + +The two Perl subs defined below provide the equivalent +functionality. =over 5 @@ -882,6 +891,9 @@ The source buffer can either be a scalar or a scalar reference. =back +Please note: the two functions defined above are I compatible with +the Unix commands of the same name. + =head1 GZIP INTERFACE A number of functions are supplied in I for reading and writing @@ -1134,7 +1146,85 @@ The buffer parameters can either be a scalar or a scalar reference. If the $crc parameters is C, the crc value will be reset. -=head1 ACCESSING ZIP FILES +=head1 FAQ + +=head2 Compatibility with Unix compress/uncompress. + +Although C has a pair of functions called C +and C, they are I the same as the Unix programs of the +same name. The C library is not compatable with Unix +C. + +If you have the C program available, you can use this to +read compressed files + + open F, "uncompress -c $filename |"; + while () + { + ... + +If you have the C program available, you can use this to read +compressed files + + open F, "gunzip -c $filename |"; + while () + { + ... + +and this to write compress files if you have the C program +available + + open F, "| compress -c $filename "; + print F "data"; + ... + close F ; + +=head2 Accessing .tar.Z files + +The C module can optionally use C (via +the C module) to access tar files that have been compressed +with C. Unfortunately tar files compressed with the Unix C +utility cannot be read by C and so cannot be directly +accesses by C. + +If the C or C programs are available, you can use +one of these workarounds to read C<.tar.Z> files from C + +Firstly with C + + use strict; + use warnings; + use Archive::Tar; + + open F, "uncompress -c $filename |"; + my $tar = Archive::Tar->new(*F); + ... + +and this with C + + use strict; + use warnings; + use Archive::Tar; + + open F, "gunzip -c $filename |"; + my $tar = Archive::Tar->new(*F); + ... + +Similarly, if the C program is available, you can use this to +write a C<.tar.Z> file + + use strict; + use warnings; + use Archive::Tar; + use IO::File; + + my $fh = newIO::File "| compress -c >$filename"; + my $tar = Archive::Tar->new(); + ... + $tar->write($fh); + $fh->close ; + +=head2 Accessing ZIP Files Although it is possible to use this module to access .zip files, there is a module on CPAN that will do all the hard work for you. Check out