1gzip(3) User Contributed Perl Documentation gzip(3)
2
3
4
6 PerlIO::gzip - Perl extension to provide a PerlIO layer to gzip/gunzip
7
9 use PerlIO::gzip;
10 open FOO, "<:gzip", "file.gz" or die $!;
11 print while <FOO>; # And it will be uncompressed...
12
13 binmode FOO, ":gzip(none)" # Starts reading deflate stream from here on
14
16 PerlIO::gzip provides a PerlIO layer that manipulates files in the
17 format used by the "gzip" program. Compression and Decompression are
18 implemented, but not together. If you attempt to open a file for
19 reading and writing the open will fail.
20
22 PerlIO::gzip exports no subroutines or symbols, just a perl layer
23 "gzip"
24
26 The "gzip" layer takes a comma separated list of arguments. 4 exclusive
27 options choose the header checking mode:
28
29 gzip
30 The default. Expects a standard gzip file header for reading,
31 writes a standard gzip file header.
32
33 none
34 Expects or writes no file header; assumes the file handle is
35 immediately a deflate stream (eg as would be found inside a "zip"
36 file)
37
38 auto
39 Potentially dangerous. If the first two bytes match the "gzip"
40 header "\x1f\x8b" then a gzip header is assumed (and checked) else
41 a deflate stream is assumed. No different from gzip on writing.
42
43 autopop
44 Potentially dangerous. If the first two bytes match the "gzip"
45 header "\x1f\x8b" then a gzip header is assumed (and checked) else
46 the layer is silently popped. This results in gzip files being
47 transparently decompressed, other files being treated normally. Of
48 course, this has sides effects such as File::Copy becoming gunzip,
49 and File::Compare comparing the uncompressed contents of files.
50
51 In autopop mode Opening a handle for writing (or reading and
52 writing) will cause the gzip layer to automatically be popped.
53
54 Optionally you can add this flag:
55
56 lazy
57 For reading, defer header checking until the first read. For
58 writing, don't write a header until the first buffer empty of
59 compressed data to disk. (and don't write anything at all if no
60 data was written to the handle)
61
62 By default, gzip header checking is done before the "open" (or
63 "binmode") returns, so if an error is detected in the gzip header
64 the "open" or "binmode" will fail. However, this will require
65 reading some data, or writing a header. With lazy set on a file
66 opened for reading the check is deferred until the first read so
67 the "open" should always succeed, but any problems with the header
68 will cause an error on read.
69
70 open FOO, "<:gzip(lazy)", "file.gz" or die $!; # Dangerous.
71 while (<FOO>) {
72 print;
73 } # Whoa. Bad. You're not distinguishing between errors and EOF.
74
75 If you're not careful you won't spot the errors - like the example
76 above you'll think you got end of file.
77
78 lazy is ignored if you are in autopop mode.
79
81 Nicholas Clark, <nwc10+perlio-gzip@colon.colondot.net>
82
84 perl, gzip, rfc 1952 <http://www.ietf.org/rfc/rfc1952.txt> (the gzip
85 file format specification), rfc 1951
86 <http://www.ietf.org/rfc/rfc1951.txt> (DEFLATE compressed data format
87 specification)
88
89
90
91perl v5.38.0 2023-07-21 gzip(3)