{
    "mode": "info",
    "parameter": "IO::Zlib",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/IO%3A%3AZlib/json",
    "generated": "2026-07-05T06:59:12Z",
    "synopsis": "With any version of Perl 5 you can use the basic OO interface:\nuse IO::Zlib;\n$fh = new IO::Zlib;\nif ($fh->open(\"file.gz\", \"rb\")) {\nprint <$fh>;\n$fh->close;\n}\n$fh = IO::Zlib->new(\"file.gz\", \"wb9\");\nif (defined $fh) {\nprint $fh \"bar\\n\";\n$fh->close;\n}\n$fh = IO::Zlib->new(\"file.gz\", \"rb\");\nif (defined $fh) {\nprint <$fh>;\nundef $fh;       # automatically closes the file\n}\nWith Perl 5.004 you can also use the TIEHANDLE interface to access\ncompressed files just like ordinary files:\nuse IO::Zlib;\ntie *FILE, 'IO::Zlib', \"file.gz\", \"wb\";\nprint FILE \"line 1\\nline2\\n\";\ntie *FILE, 'IO::Zlib', \"file.gz\", \"rb\";\nwhile (<FILE>) { print \"LINE: \", $ };",
    "sections": {
        "NAME": {
            "content": "IO::Zlib - IO:: style interface to Compress::Zlib\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "With any version of Perl 5 you can use the basic OO interface:\n\nuse IO::Zlib;\n\n$fh = new IO::Zlib;\nif ($fh->open(\"file.gz\", \"rb\")) {\nprint <$fh>;\n$fh->close;\n}\n\n$fh = IO::Zlib->new(\"file.gz\", \"wb9\");\nif (defined $fh) {\nprint $fh \"bar\\n\";\n$fh->close;\n}\n\n$fh = IO::Zlib->new(\"file.gz\", \"rb\");\nif (defined $fh) {\nprint <$fh>;\nundef $fh;       # automatically closes the file\n}\n\nWith Perl 5.004 you can also use the TIEHANDLE interface to access\ncompressed files just like ordinary files:\n\nuse IO::Zlib;\n\ntie *FILE, 'IO::Zlib', \"file.gz\", \"wb\";\nprint FILE \"line 1\\nline2\\n\";\n\ntie *FILE, 'IO::Zlib', \"file.gz\", \"rb\";\nwhile (<FILE>) { print \"LINE: \", $ };\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"IO::Zlib\" provides an IO:: style interface to Compress::Zlib and hence\nto gzip/zlib compressed files. It provides many of the same methods as\nthe IO::Handle interface.\n\nStarting from IO::Zlib version 1.02, IO::Zlib can also use an external\ngzip command.  The default behaviour is to try to use an external gzip\nif no \"Compress::Zlib\" can be loaded, unless explicitly disabled by\n\nuse IO::Zlib qw(:gzipexternal 0);\n\nIf explicitly enabled by\n\nuse IO::Zlib qw(:gzipexternal 1);\n\nthen the external gzip is used instead of \"Compress::Zlib\".\n",
            "subsections": []
        },
        "CONSTRUCTOR": {
            "content": "new ( [ARGS] )\nCreates an \"IO::Zlib\" object. If it receives any parameters, they\nare passed to the method \"open\"; if the open fails, the object is\ndestroyed.  Otherwise, it is returned to the caller.\n",
            "subsections": []
        },
        "OBJECT METHODS": {
            "content": "open ( FILENAME, MODE )\n\"open\" takes two arguments. The first is the name of the file to\nopen and the second is the open mode. The mode can be anything\nacceptable to Compress::Zlib and by extension anything acceptable\nto zlib (that basically means POSIX fopen() style mode strings plus\nan optional number to indicate the compression level).\n\nopened\nReturns true if the object currently refers to a opened file.\n\nclose\nClose the file associated with the object and disassociate the file\nfrom the handle.  Done automatically on destroy.\n\ngetc\nReturn the next character from the file, or undef if none remain.\n\ngetline\nReturn the next line from the file, or undef on end of string.  Can\nsafely be called in an array context.  Currently ignores $/\n($INPUTRECORDSEPARATOR or $RS when English is in use) and treats\nlines as delimited by \"\\n\".\n\ngetlines\nGet all remaining lines from the file.  It will croak() if\naccidentally called in a scalar context.\n\nprint ( ARGS... )\nPrint ARGS to the  file.\n\nread ( BUF, NBYTES, [OFFSET] )\nRead some bytes from the file.  Returns the number of bytes\nactually read, 0 on end-of-file, undef on error.\n\neof Returns true if the handle is currently positioned at end of file?\n\nseek ( OFFSET, WHENCE )\nSeek to a given position in the stream.  Not yet supported.\n\ntell\nReturn the current position in the stream, as a numeric offset.\nNot yet supported.\n\nsetpos ( POS )\nSet the current position, using the opaque value returned by\n\"getpos()\".  Not yet supported.\n\ngetpos ( POS )\nReturn the current position in the string, as an opaque object.\nNot yet supported.\n",
            "subsections": []
        },
        "USING THE EXTERNAL GZIP": {
            "content": "If the external gzip is used, the following \"open\"s are used:\n\nopen(FH, \"gzip -dc $filename |\")  # for read opens\nopen(FH, \" | gzip > $filename\")   # for write opens\n\nYou can modify the 'commands' for example to hardwire an absolute path\nby e.g.\n\nuse IO::Zlib ':gzipreadopen'  => '/some/where/gunzip -c %s |';\nuse IO::Zlib ':gzipwriteopen' => '| /some/where/gzip.exe > %s';\n\nThe %s is expanded to be the filename (\"sprintf\" is used, so be careful\nto escape any other \"%\" signs).  The 'commands' are checked for sanity\n- they must contain the %s, and the read open must end with the pipe\nsign, and the write open must begin with the pipe sign.\n",
            "subsections": []
        },
        "CLASS METHODS": {
            "content": "hasCompressZlib\nReturns true if \"Compress::Zlib\" is available.  Note that this does\nnot mean that \"Compress::Zlib\" is being used: see \"gzipexternal\"\nand gzipused.\n\ngzipexternal\nUndef if an external gzip can be used if \"Compress::Zlib\" is not\navailable (see \"hasCompressZlib\"), true if an external gzip is\nexplicitly used, false if an external gzip must not be used.  See\n\"gzipused\".\n\ngzipused\nTrue if an external gzip is being used, false if not.\n\ngzipreadopen\nReturn the 'command' being used for opening a file for reading\nusing an external gzip.\n\ngzipwriteopen\nReturn the 'command' being used for opening a file for writing\nusing an external gzip.\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "IO::Zlib::getlines: must be called in list context\nIf you want read lines, you must read in list context.\n\nIO::Zlib::gzopenexternal: mode '...' is illegal\nUse only modes 'rb' or 'wb' or /wb[1-9]/.\n\nIO::Zlib::import: '...' is illegal\nThe known import symbols are the \":gzipexternal\",\n\":gzipreadopen\", and \":gzipwriteopen\".  Anything else is not\nrecognized.\n\nIO::Zlib::import: ':gzipexternal' requires an argument\nThe \":gzipexternal\" requires one boolean argument.\n\nIO::Zlib::import: 'gzipreadopen' requires an argument\nThe \":gzipexternal\" requires one string argument.\n\nIO::Zlib::import: 'gzipread' '...' is illegal\nThe \":gzipreadopen\" argument must end with the pipe sign (|) and\nhave the %s for the filename.  See \"USING THE EXTERNAL GZIP\".\n\nIO::Zlib::import: 'gzipwriteopen' requires an argument\nThe \":gzipexternal\" requires one string argument.\n\nIO::Zlib::import: 'gzipwriteopen' '...' is illegal\nThe \":gzipwriteopen\" argument must begin with the pipe sign (|)\nand have the %s for the filename.  An output redirect (>) is also\noften a good idea, depending on your operating system shell syntax.\nSee \"USING THE EXTERNAL GZIP\".\n\nIO::Zlib::import: no Compress::Zlib and no external gzip\nGiven that we failed to load \"Compress::Zlib\" and that the use of\nan external gzip was disabled, IO::Zlib has not much chance of\nworking.\n\nIO::Zlib::open: needs a filename\nNo filename, no open.\n\nIO::Zlib::READ: NBYTES must be specified\nWe must know how much to read.\n\nIO::Zlib::WRITE: too long LENGTH\nThe LENGTH must be less than or equal to the buffer size.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "perlfunc, \"I/O Operators\" in perlop, IO::Handle, Compress::Zlib\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "Created by Tom Hughes <tom@compton.nu>.\n\nSupport for external gzip added by Jarkko Hietaniemi <jhi@iki.fi>.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 1998-2004 Tom Hughes <tom@compton.nu>.  All rights\nreserved. This program is free software; you can redistribute it and/or\nmodify it under the same terms as Perl itself.\n\nperl v5.34.0                      2026-06-23                   IO::Zlib(3perl)",
            "subsections": []
        }
    },
    "summary": "IO::Zlib - IO:: style interface to Compress::Zlib",
    "flags": [],
    "examples": [],
    "see_also": []
}