.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.47)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Required to disable full justification in groff 1.23.0.
.if n .ds AD l
.\" ========================================================================
.\"
.IX Title "Zlib 3"
.TH Zlib 3 2026-01-17 "perl v5.42.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
IO::Zlib \- IO:: style interface to Compress::Zlib
.SH SYNOPSIS
.IX Header "SYNOPSIS"
With any version of Perl 5 you can use the basic OO interface:
.PP
.Vb 1
\&    use IO::Zlib;
\&
\&    $fh = new IO::Zlib;
\&    if ($fh\->open("file.gz", "rb")) {
\&        print <$fh>;
\&        $fh\->close;
\&    }
\&
\&    $fh = IO::Zlib\->new("file.gz", "wb9");
\&    if (defined $fh) {
\&        print $fh "bar\en";
\&        $fh\->close;
\&    }
\&
\&    $fh = IO::Zlib\->new("file.gz", "rb");
\&    if (defined $fh) {
\&        print <$fh>;
\&        undef $fh;       # automatically closes the file
\&    }
.Ve
.PP
With Perl 5.004 you can also use the TIEHANDLE interface to access
compressed files just like ordinary files:
.PP
.Vb 1
\&    use IO::Zlib;
\&
\&    tie *FILE, \*(AqIO::Zlib\*(Aq, "file.gz", "wb";
\&    print FILE "line 1\enline2\en";
\&
\&    tie *FILE, \*(AqIO::Zlib\*(Aq, "file.gz", "rb";
\&    while (<FILE>) { print "LINE: ", $_ };
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
\&\f(CW\*(C`IO::Zlib\*(C'\fR provides an IO:: style interface to Compress::Zlib and
hence to gzip/zlib compressed files. It provides many of the same methods
as the IO::Handle interface.
.PP
Starting from IO::Zlib version 1.02, IO::Zlib can also use an
external \fIgzip\fR command.  The default behaviour is to try to use
an external \fIgzip\fR if no \f(CW\*(C`Compress::Zlib\*(C'\fR can be loaded, unless
explicitly disabled by
.PP
.Vb 1
\&    use IO::Zlib qw(:gzip_external 0);
.Ve
.PP
If explicitly enabled by
.PP
.Vb 1
\&    use IO::Zlib qw(:gzip_external 1);
.Ve
.PP
then the external \fIgzip\fR is used \fBinstead\fR of \f(CW\*(C`Compress::Zlib\*(C'\fR.
.SH CONSTRUCTOR
.IX Header "CONSTRUCTOR"
.IP "new ( [ARGS] )" 4
.IX Item "new ( [ARGS] )"
Creates an \f(CW\*(C`IO::Zlib\*(C'\fR object. If it receives any parameters, they are
passed to the method \f(CW\*(C`open\*(C'\fR; if the open fails, the object is destroyed.
Otherwise, it is returned to the caller.
.SH "OBJECT METHODS"
.IX Header "OBJECT METHODS"
.IP "open ( FILENAME, MODE )" 4
.IX Item "open ( FILENAME, MODE )"
\&\f(CW\*(C`open\*(C'\fR takes two arguments. The first is the name of the file to open
and the second is the open mode. The mode can be anything acceptable to
Compress::Zlib and by extension anything acceptable to \fIzlib\fR (that
basically means POSIX \fBfopen()\fR style mode strings plus an optional number
to indicate the compression level).
.IP opened 4
.IX Item "opened"
Returns true if the object currently refers to a opened file.
.IP close 4
.IX Item "close"
Close the file associated with the object and disassociate
the file from the handle.
Done automatically on destroy.
.IP getc 4
.IX Item "getc"
Return the next character from the file, or undef if none remain.
.IP getline 4
.IX Item "getline"
Return the next line from the file, or undef on end of string.
Can safely be called in an array context.
Currently ignores $/ ($INPUT_RECORD_SEPARATOR or \f(CW$RS\fR when English
is in use) and treats lines as delimited by "\en".
.IP getlines 4
.IX Item "getlines"
Get all remaining lines from the file.
It will \fBcroak()\fR if accidentally called in a scalar context.
.IP "print ( ARGS... )" 4
.IX Item "print ( ARGS... )"
Print ARGS to the  file.
.IP "read ( BUF, NBYTES, [OFFSET] )" 4
.IX Item "read ( BUF, NBYTES, [OFFSET] )"
Read some bytes from the file.
Returns the number of bytes actually read, 0 on end\-of\-file, undef on error.
.IP eof 4
.IX Item "eof"
Returns true if the handle is currently positioned at end of file?
.IP "seek ( OFFSET, WHENCE )" 4
.IX Item "seek ( OFFSET, WHENCE )"
Seek to a given position in the stream.
Not yet supported.
.IP tell 4
.IX Item "tell"
Return the current position in the stream, as a numeric offset.
Not yet supported.
.IP "setpos ( POS )" 4
.IX Item "setpos ( POS )"
Set the current position, using the opaque value returned by \f(CWgetpos()\fR.
Not yet supported.
.IP "getpos ( POS )" 4
.IX Item "getpos ( POS )"
Return the current position in the string, as an opaque object.
Not yet supported.
.SH "USING THE EXTERNAL GZIP"
.IX Header "USING THE EXTERNAL GZIP"
If the external \fIgzip\fR is used, the following \f(CW\*(C`open\*(C'\fRs are used:
.PP
.Vb 2
\&    open(FH, "gzip \-dc $filename |")  # for read opens
\&    open(FH, " | gzip > $filename")   # for write opens
.Ve
.PP
You can modify the \*(Aqcommands\*(Aq for example to hardwire
an absolute path by e.g.
.PP
.Vb 2
\&    use IO::Zlib \*(Aq:gzip_read_open\*(Aq  => \*(Aq/some/where/gunzip \-c %s |\*(Aq;
\&    use IO::Zlib \*(Aq:gzip_write_open\*(Aq => \*(Aq| /some/where/gzip.exe > %s\*(Aq;
.Ve
.PP
The \f(CW%s\fR is expanded to be the filename (\f(CW\*(C`sprintf\*(C'\fR is used, so be
careful to escape any other \f(CW\*(C`%\*(C'\fR signs).  The \*(Aqcommands\*(Aq are checked
for sanity \- they must contain the \f(CW%s\fR, and the read open must end
with the pipe sign, and the write open must begin with the pipe sign.
.SH "CLASS METHODS"
.IX Header "CLASS METHODS"
.IP has_Compress_Zlib 4
.IX Item "has_Compress_Zlib"
Returns true if \f(CW\*(C`Compress::Zlib\*(C'\fR is available.  Note that this does
not mean that \f(CW\*(C`Compress::Zlib\*(C'\fR is being used: see "gzip_external"
and gzip_used.
.IP gzip_external 4
.IX Item "gzip_external"
Undef if an external \fIgzip\fR \fBcan\fR be used if \f(CW\*(C`Compress::Zlib\*(C'\fR is
not available (see "has_Compress_Zlib"), true if an external \fIgzip\fR
is explicitly used, false if an external \fIgzip\fR must not be used.
See "gzip_used".
.IP gzip_used 4
.IX Item "gzip_used"
True if an external \fIgzip\fR is being used, false if not.
.IP gzip_read_open 4
.IX Item "gzip_read_open"
Return the \*(Aqcommand\*(Aq being used for opening a file for reading using an
external \fIgzip\fR.
.IP gzip_write_open 4
.IX Item "gzip_write_open"
Return the \*(Aqcommand\*(Aq being used for opening a file for writing using an
external \fIgzip\fR.
.SH DIAGNOSTICS
.IX Header "DIAGNOSTICS"
.IP "IO::Zlib::getlines: must be called in list context" 4
.IX Item "IO::Zlib::getlines: must be called in list context"
If you want read lines, you must read in list context.
.IP "IO::Zlib::gzopen_external: mode \*(Aq...\*(Aq is illegal" 4
.IX Item "IO::Zlib::gzopen_external: mode '...' is illegal"
Use only modes \*(Aqrb\*(Aq or \*(Aqwb\*(Aq or /wb[1\-9]/.
.IP "IO::Zlib::import: \*(Aq...\*(Aq is illegal" 4
.IX Item "IO::Zlib::import: '...' is illegal"
The known import symbols are the \f(CW\*(C`:gzip_external\*(C'\fR, \f(CW\*(C`:gzip_read_open\*(C'\fR,
and \f(CW\*(C`:gzip_write_open\*(C'\fR.  Anything else is not recognized.
.IP "IO::Zlib::import: \*(Aq:gzip_external\*(Aq requires an argument" 4
.IX Item "IO::Zlib::import: ':gzip_external' requires an argument"
The \f(CW\*(C`:gzip_external\*(C'\fR requires one boolean argument.
.IP "IO::Zlib::import: \*(Aqgzip_read_open\*(Aq requires an argument" 4
.IX Item "IO::Zlib::import: 'gzip_read_open' requires an argument"
The \f(CW\*(C`:gzip_external\*(C'\fR requires one string argument.
.IP "IO::Zlib::import: \*(Aqgzip_read\*(Aq \*(Aq...\*(Aq is illegal" 4
.IX Item "IO::Zlib::import: 'gzip_read' '...' is illegal"
The \f(CW\*(C`:gzip_read_open\*(C'\fR argument must end with the pipe sign (|)
and have the \f(CW%s\fR for the filename.  See "USING THE EXTERNAL GZIP".
.IP "IO::Zlib::import: \*(Aqgzip_write_open\*(Aq requires an argument" 4
.IX Item "IO::Zlib::import: 'gzip_write_open' requires an argument"
The \f(CW\*(C`:gzip_external\*(C'\fR requires one string argument.
.IP "IO::Zlib::import: \*(Aqgzip_write_open\*(Aq \*(Aq...\*(Aq is illegal" 4
.IX Item "IO::Zlib::import: 'gzip_write_open' '...' is illegal"
The \f(CW\*(C`:gzip_write_open\*(C'\fR argument must begin with the pipe sign (|)
and have the \f(CW%s\fR for the filename.  An output redirect (>) is also
often a good idea, depending on your operating system shell syntax.
See "USING THE EXTERNAL GZIP".
.IP "IO::Zlib::import: no Compress::Zlib and no external gzip" 4
.IX Item "IO::Zlib::import: no Compress::Zlib and no external gzip"
Given that we failed to load \f(CW\*(C`Compress::Zlib\*(C'\fR and that the use of
 an external \fIgzip\fR was disabled, IO::Zlib has not much chance of working.
.IP "IO::Zlib::open: needs a filename" 4
.IX Item "IO::Zlib::open: needs a filename"
No filename, no open.
.IP "IO::Zlib::READ: NBYTES must be specified" 4
.IX Item "IO::Zlib::READ: NBYTES must be specified"
We must know how much to read.
.IP "IO::Zlib::WRITE: too long LENGTH" 4
.IX Item "IO::Zlib::WRITE: too long LENGTH"
The LENGTH must be less than or equal to the buffer size.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
perlfunc,
"I/O Operators" in perlop,
IO::Handle,
Compress::Zlib
.SH HISTORY
.IX Header "HISTORY"
Created by Tom Hughes <\fItom@compton.nu\fR>.
.PP
Support for external gzip added by Jarkko Hietaniemi <\fIjhi@iki.fi\fR>.
.SH COPYRIGHT
.IX Header "COPYRIGHT"
Copyright (c) 1998\-2004 Tom Hughes <\fItom@compton.nu\fR>.
All rights reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
