gzip(3) | User Contributed Perl Documentation | gzip(3) |
PerlIO::gzip - Perl extension to provide a PerlIO layer to gzip/gunzip
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
PerlIO::gzip provides a PerlIO layer that manipulates files in the format used by the "gzip" program. Compression and Decompression are implemented, but not together. If you attempt to open a file for reading and writing the open will fail.
PerlIO::gzip exports no subroutines or symbols, just a perl layer "gzip"
The "gzip" layer takes a comma separated list of arguments. 4 exclusive options choose the header checking mode:
In autopop mode Opening a handle for writing (or reading and writing) will cause the gzip layer to automatically be popped.
Optionally you can add this flag:
By default, gzip header checking is done before the "open" (or "binmode") returns, so if an error is detected in the gzip header the "open" or "binmode" will fail. However, this will require reading some data, or writing a header. With lazy set on a file opened for reading the check is deferred until the first read so the "open" 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.
lazy is ignored if you are in autopop mode.
Nicholas Clark, <nwc10+perlio-gzip@colon.colondot.net>
perl, gzip, rfc 1952 <http://www.ietf.org/rfc/rfc1952.txt> (the gzip file format specification), rfc 1951 <http://www.ietf.org/rfc/rfc1951.txt> (DEFLATE compressed data format specification)
2017-06-21 | perl v5.34.0 |