NAME
PerlIO::gzip - Perl extension to provide a PerlIO layer to gzip/gunzip
SYNOPSIS
use PerlIO::gzip;
open FOO, "<:gzip", "file.gz" or die $!;
print while <FOO>; # And it will be uncompressed.
binmode FOO, ":gzip(none)" # Starts reading deflate stream from here on.
DESCRIPTION
PerlIO::gzip provides a PerlIO layer that manipulates files in the format used by the gzip
program. Currently only decompression is implemented.
EXPORT
PerlIO::gzip exports no subroutines or symbols, just a perl layer gzip
LAYER ARGUMENTS
The gzip
layer takes a comma separated list of arguments. 3 exclusive options choose the header checking mode:
- gzip
-
The default. Expects a standard gzip file header
- none
-
Expects no file header; assumes the file handle is immediately a deflate stream (eg as would be found inside a
zip
file) - auto
-
Potentially dangerous. If the first two bytes match the
gzip
header "\x1f\x8b" then a gzip header is assumed (and checked) else a deflate stream is assumed
Optionally you can add this flag:
- lazy
-
Defer header checking until the first read. By default, gzip header checking is done before the
open
(orbinmode
) returns, so if an error is detected in the gzip header theopen
orbinmode
will fail. However, this will require reading some data. With lazy set the check is deferred until the first read, so theopen
should always succeed, but any problems with the header will cause an error on read.open FOO, "<:gzip(lazy)", "file.gz" or die $!; # Dangerous. while (<FOO>) { print; } # Whoa. Bad. You're not distinguishing between errors and EOF.
If you're not careful you won't spot the errors - like the example above you'll think you got end of file.
AUTHOR
Nicholas Clark, <nick@talking.bollo.cx>