{
    "mode": "perldoc",
    "parameter": "IO::Uncompress::Inflate",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/IO%3A%3AUncompress%3A%3AInflate/json",
    "generated": "2026-06-03T06:46:22Z",
    "synopsis": "use IO::Uncompress::Inflate qw(inflate $InflateError) ;\nmy $status = inflate $input => $output [,OPTS]\nor die \"inflate failed: $InflateError\\n\";\nmy $z = IO::Uncompress::Inflate->new( $input [OPTS] )\nor die \"inflate failed: $InflateError\\n\";\n$status = $z->read($buffer)\n$status = $z->read($buffer, $length)\n$status = $z->read($buffer, $length, $offset)\n$line = $z->getline()\n$char = $z->getc()\n$char = $z->ungetc()\n$char = $z->opened()\n$status = $z->inflateSync()\n$data = $z->trailingData()\n$status = $z->nextStream()\n$data = $z->getHeaderInfo()\n$z->tell()\n$z->seek($position, $whence)\n$z->binmode()\n$z->fileno()\n$z->eof()\n$z->close()\n$InflateError ;\n# IO::File mode\n<$z>\nread($z, $buffer);\nread($z, $buffer, $length);\nread($z, $buffer, $length, $offset);\ntell($z)\nseek($z, $position, $whence)\nbinmode($z)\nfileno($z)\neof($z)\nclose($z)",
    "sections": {
        "NAME": {
            "content": "IO::Uncompress::Inflate - Read RFC 1950 files/buffers\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use IO::Uncompress::Inflate qw(inflate $InflateError) ;\n\nmy $status = inflate $input => $output [,OPTS]\nor die \"inflate failed: $InflateError\\n\";\n\nmy $z = IO::Uncompress::Inflate->new( $input [OPTS] )\nor die \"inflate failed: $InflateError\\n\";\n\n$status = $z->read($buffer)\n$status = $z->read($buffer, $length)\n$status = $z->read($buffer, $length, $offset)\n$line = $z->getline()\n$char = $z->getc()\n$char = $z->ungetc()\n$char = $z->opened()\n\n$status = $z->inflateSync()\n\n$data = $z->trailingData()\n$status = $z->nextStream()\n$data = $z->getHeaderInfo()\n$z->tell()\n$z->seek($position, $whence)\n$z->binmode()\n$z->fileno()\n$z->eof()\n$z->close()\n\n$InflateError ;\n\n# IO::File mode\n\n<$z>\nread($z, $buffer);\nread($z, $buffer, $length);\nread($z, $buffer, $length, $offset);\ntell($z)\nseek($z, $position, $whence)\nbinmode($z)\nfileno($z)\neof($z)\nclose($z)\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides a Perl interface that allows the reading of files/buffers that conform to\nRFC 1950.\n\nFor writing RFC 1950 files/buffers, see the companion module IO::Compress::Deflate.\n",
            "subsections": []
        },
        "Functional Interface": {
            "content": "A top-level function, \"inflate\", is provided to carry out \"one-shot\" uncompression between\nbuffers and/or files. For finer control over the uncompression process, see the \"OO Interface\"\nsection.\n\nuse IO::Uncompress::Inflate qw(inflate $InflateError) ;\n\ninflate $inputfilenameorreference => $outputfilenameorreference [,OPTS]\nor die \"inflate failed: $InflateError\\n\";\n\nThe functional interface needs Perl5.005 or better.\n\ninflate $inputfilenameorreference => $outputfilenameorreference [, OPTS]\n\"inflate\" expects at least two parameters, $inputfilenameorreference and\n$outputfilenameorreference and zero or more optional parameters (see \"Optional Parameters\")\n\nThe $inputfilenameorreference parameter\nThe parameter, $inputfilenameorreference, is used to define the source of the compressed\ndata.\n\nIt can take one of the following forms:\n\nA filename\nIf the $inputfilenameorreference parameter is a simple scalar, it is assumed to be a\nfilename. This file will be opened for reading and the input data will be read from it.\n\nA filehandle\nIf the $inputfilenameorreference parameter is a filehandle, the input data will be read\nfrom it. The string '-' can be used as an alias for standard input.\n\nA scalar reference\nIf $inputfilenameorreference is a scalar reference, the input data will be read from\n$$inputfilenameorreference.\n\nAn array reference\nIf $inputfilenameorreference is an array reference, each element in the array must be a\nfilename.\n\nThe input data will be read from each file in turn.\n\nThe complete array will be walked to ensure that it only contains valid filenames before\nany data is uncompressed.\n\nAn Input FileGlob string\nIf $inputfilenameorreference is a string that is delimited by the characters \"<\" and \">\"\n\"inflate\" will assume that it is an *input fileglob string*. The input is the list of files\nthat match the fileglob.\n\nSee File::GlobMapper for more details.\n\nIf the $inputfilenameorreference parameter is any other type, \"undef\" will be returned.\n\nThe $outputfilenameorreference parameter\nThe parameter $outputfilenameorreference is used to control the destination of the\nuncompressed data. This parameter can take one of these forms.\n\nA filename\nIf the $outputfilenameorreference parameter is a simple scalar, it is assumed to be a\nfilename. This file will be opened for writing and the uncompressed data will be written to\nit.\n\nA filehandle\nIf the $outputfilenameorreference parameter is a filehandle, the uncompressed data will\nbe written to it. The string '-' can be used as an alias for standard output.\n\nA scalar reference\nIf $outputfilenameorreference is a scalar reference, the uncompressed data will be\nstored in $$outputfilenameorreference.\n\nAn Array Reference\nIf $outputfilenameorreference is an array reference, the uncompressed data will be\npushed onto the array.\n\nAn Output FileGlob\nIf $outputfilenameorreference is a string that is delimited by the characters \"<\" and\n\">\" \"inflate\" will assume that it is an *output fileglob string*. The output is the list of\nfiles that match the fileglob.\n\nWhen $outputfilenameorreference is an fileglob string, $inputfilenameorreference must\nalso be a fileglob string. Anything else is an error.\n\nSee File::GlobMapper for more details.\n\nIf the $outputfilenameorreference parameter is any other type, \"undef\" will be returned.\n",
            "subsections": [
                {
                    "name": "Notes",
                    "content": "When $inputfilenameorreference maps to multiple compressed files/buffers and\n$outputfilenameorreference is a single file/buffer, after uncompression\n$outputfilenameorreference will contain a concatenation of all the uncompressed data from\neach of the input files/buffers.\n"
                },
                {
                    "name": "Optional Parameters",
                    "content": "The optional parameters for the one-shot function \"inflate\" are (for the most part) identical to\nthose used with the OO interface defined in the \"Constructor Options\" section. The exceptions\nare listed below\n\n\"AutoClose => 0|1\"\nThis option applies to any input or output data streams to \"inflate\" that are filehandles.\n\nIf \"AutoClose\" is specified, and the value is true, it will result in all input and/or\noutput filehandles being closed once \"inflate\" has completed.\n\nThis parameter defaults to 0.\n\n\"BinModeOut => 0|1\"\nThis option is now a no-op. All files will be written in binmode.\n\n\"Append => 0|1\"\nThe behaviour of this option is dependent on the type of output data stream.\n\n*    A Buffer\n\nIf \"Append\" is enabled, all uncompressed data will be append to the end of the output\nbuffer. Otherwise the output buffer will be cleared before any uncompressed data is\nwritten to it.\n\n*    A Filename\n\nIf \"Append\" is enabled, the file will be opened in append mode. Otherwise the contents\nof the file, if any, will be truncated before any uncompressed data is written to it.\n\n*    A Filehandle\n\nIf \"Append\" is enabled, the filehandle will be positioned to the end of the file via a\ncall to \"seek\" before any uncompressed data is written to it. Otherwise the file\npointer will not be moved.\n\nWhen \"Append\" is specified, and set to true, it will *append* all uncompressed data to the\noutput data stream.\n\nSo when the output is a filehandle it will carry out a seek to the eof before writing any\nuncompressed data. If the output is a filename, it will be opened for appending. If the\noutput is a buffer, all uncompressed data will be appended to the existing buffer.\n\nConversely when \"Append\" is not specified, or it is present and is set to false, it will\noperate as follows.\n\nWhen the output is a filename, it will truncate the contents of the file before writing any\nuncompressed data. If the output is a filehandle its position will not be changed. If the\noutput is a buffer, it will be wiped before any uncompressed data is output.\n\nDefaults to 0.\n\n\"MultiStream => 0|1\"\nIf the input file/buffer contains multiple compressed data streams, this option will\nuncompress the whole lot as a single data stream.\n\nDefaults to 0.\n\n\"TrailingData => $scalar\"\nReturns the data, if any, that is present immediately after the compressed data stream once\nuncompression is complete.\n\nThis option can be used when there is useful information immediately following the\ncompressed data stream, and you don't know the length of the compressed data stream.\n\nIf the input is a buffer, \"trailingData\" will return everything from the end of the\ncompressed data stream to the end of the buffer.\n\nIf the input is a filehandle, \"trailingData\" will return the data that is left in the\nfilehandle input buffer once the end of the compressed data stream has been reached. You\ncan then use the filehandle to read the rest of the input file.\n\nDon't bother using \"trailingData\" if the input is a filename.\n\nIf you know the length of the compressed data stream before you start uncompressing, you\ncan avoid having to use \"trailingData\" by setting the \"InputLength\" option.\n"
                },
                {
                    "name": "Examples",
                    "content": "To read the contents of the file \"file1.txt.1950\" and write the uncompressed data to the file\n\"file1.txt\".\n\nuse strict ;\nuse warnings ;\nuse IO::Uncompress::Inflate qw(inflate $InflateError) ;\n\nmy $input = \"file1.txt.1950\";\nmy $output = \"file1.txt\";\ninflate $input => $output\nor die \"inflate failed: $InflateError\\n\";\n\nTo read from an existing Perl filehandle, $input, and write the uncompressed data to a buffer,\n$buffer.\n\nuse strict ;\nuse warnings ;\nuse IO::Uncompress::Inflate qw(inflate $InflateError) ;\nuse IO::File ;\n\nmy $input = IO::File->new( \"<file1.txt.1950\" )\nor die \"Cannot open 'file1.txt.1950': $!\\n\" ;\nmy $buffer ;\ninflate $input => \\$buffer\nor die \"inflate failed: $InflateError\\n\";\n\nTo uncompress all files in the directory \"/my/home\" that match \"*.txt.1950\" and store the\ncompressed data in the same directory\n\nuse strict ;\nuse warnings ;\nuse IO::Uncompress::Inflate qw(inflate $InflateError) ;\n\ninflate '</my/home/*.txt.1950>' => '</my/home/#1.txt>'\nor die \"inflate failed: $InflateError\\n\";\n\nand if you want to compress each file one at a time, this will do the trick\n\nuse strict ;\nuse warnings ;\nuse IO::Uncompress::Inflate qw(inflate $InflateError) ;\n\nfor my $input ( glob \"/my/home/*.txt.1950\" )\n{\nmy $output = $input;\n$output =~ s/.1950// ;\ninflate $input => $output\nor die \"Error compressing '$input': $InflateError\\n\";\n}\n\nOO Interface"
                },
                {
                    "name": "Constructor",
                    "content": "The format of the constructor for IO::Uncompress::Inflate is shown below\n\nmy $z = IO::Uncompress::Inflate->new( $input [OPTS] )\nor die \"IO::Uncompress::Inflate failed: $InflateError\\n\";\n\nReturns an \"IO::Uncompress::Inflate\" object on success and undef on failure. The variable\n$InflateError will contain an error message on failure.\n\nIf you are running Perl 5.005 or better the object, $z, returned from IO::Uncompress::Inflate\ncan be used exactly like an IO::File filehandle. This means that all normal input file\noperations can be carried out with $z. For example, to read a line from a compressed file/buffer\nyou can use either of these forms\n\n$line = $z->getline();\n$line = <$z>;\n\nThe mandatory parameter $input is used to determine the source of the compressed data. This\nparameter can take one of three forms.\n\nA filename\nIf the $input parameter is a scalar, it is assumed to be a filename. This file will be\nopened for reading and the compressed data will be read from it.\n\nA filehandle\nIf the $input parameter is a filehandle, the compressed data will be read from it. The\nstring '-' can be used as an alias for standard input.\n\nA scalar reference\nIf $input is a scalar reference, the compressed data will be read from $$input.\n"
                },
                {
                    "name": "Constructor Options",
                    "content": "The option names defined below are case insensitive and can be optionally prefixed by a '-'. So\nall of the following are valid\n"
                },
                {
                    "name": "-AutoClose",
                    "content": ""
                },
                {
                    "name": "-autoclose",
                    "content": "AUTOCLOSE\nautoclose\n\nOPTS is a combination of the following options:\n\n\"AutoClose => 0|1\"\nThis option is only valid when the $input parameter is a filehandle. If specified, and the\nvalue is true, it will result in the file being closed once either the \"close\" method is\ncalled or the IO::Uncompress::Inflate object is destroyed.\n\nThis parameter defaults to 0.\n\n\"MultiStream => 0|1\"\nAllows multiple concatenated compressed streams to be treated as a single compressed\nstream. Decompression will stop once either the end of the file/buffer is reached, an error\nis encountered (premature eof, corrupt compressed data) or the end of a stream is not\nimmediately followed by the start of another stream.\n\nThis parameter defaults to 0.\n\n\"Prime => $string\"\nThis option will uncompress the contents of $string before processing the input\nfile/buffer.\n\nThis option can be useful when the compressed data is embedded in another file/data\nstructure and it is not possible to work out where the compressed data begins without\nhaving to read the first few bytes. If this is the case, the uncompression can be *primed*\nwith these bytes using this option.\n\n\"Transparent => 0|1\"\nIf this option is set and the input file/buffer is not compressed data, the module will\nallow reading of it anyway.\n\nIn addition, if the input file/buffer does contain compressed data and there is\nnon-compressed data immediately following it, setting this option will make this module\ntreat the whole file/buffer as a single data stream.\n\nThis option defaults to 1.\n\n\"BlockSize => $num\"\nWhen reading the compressed input data, IO::Uncompress::Inflate will read it in blocks of\n$num bytes.\n\nThis option defaults to 4096.\n\n\"InputLength => $size\"\nWhen present this option will limit the number of compressed bytes read from the input\nfile/buffer to $size. This option can be used in the situation where there is useful data\ndirectly after the compressed data stream and you know beforehand the exact length of the\ncompressed data stream.\n\nThis option is mostly used when reading from a filehandle, in which case the file pointer\nwill be left pointing to the first byte directly after the compressed data stream.\n\nThis option defaults to off.\n\n\"Append => 0|1\"\nThis option controls what the \"read\" method does with uncompressed data.\n\nIf set to 1, all uncompressed data will be appended to the output parameter of the \"read\"\nmethod.\n\nIf set to 0, the contents of the output parameter of the \"read\" method will be overwritten\nby the uncompressed data.\n\nDefaults to 0.\n\n\"Strict => 0|1\"\nThis option controls whether the extra checks defined below are used when carrying out the\ndecompression. When Strict is on, the extra tests are carried out, when Strict is off they\nare not.\n\nThe default for this option is off.\n\n1    The ADLER32 checksum field must be present.\n\n2    The value of the ADLER32 field read must match the adler32 value of the uncompressed\ndata actually contained in the file.\n"
                },
                {
                    "name": "Examples",
                    "content": "TODO\n"
                }
            ]
        },
        "Methods": {
            "content": "read\nUsage is\n\n$status = $z->read($buffer)\n\nReads a block of compressed data (the size of the compressed block is determined by the \"Buffer\"\noption in the constructor), uncompresses it and writes any uncompressed data into $buffer. If\nthe \"Append\" parameter is set in the constructor, the uncompressed data will be appended to the\n$buffer parameter. Otherwise $buffer will be overwritten.\n\nReturns the number of uncompressed bytes written to $buffer, zero if eof or a negative number on\nerror.\n\nread\nUsage is\n\n$status = $z->read($buffer, $length)\n$status = $z->read($buffer, $length, $offset)\n\n$status = read($z, $buffer, $length)\n$status = read($z, $buffer, $length, $offset)\n\nAttempt to read $length bytes of uncompressed data into $buffer.\n\nThe main difference between this form of the \"read\" method and the previous one, is that this\none will attempt to return *exactly* $length bytes. The only circumstances that this function\nwill not is if end-of-file or an IO error is encountered.\n\nReturns the number of uncompressed bytes written to $buffer, zero if eof or a negative number on\nerror.\n\ngetline\nUsage is\n\n$line = $z->getline()\n$line = <$z>\n\nReads a single line.\n\nThis method fully supports the use of the variable $/ (or $INPUTRECORDSEPARATOR or $RS when\n\"English\" is in use) to determine what constitutes an end of line. Paragraph mode, record mode\nand file slurp mode are all supported.\n\ngetc\nUsage is\n\n$char = $z->getc()\n\nRead a single character.\n\nungetc\nUsage is\n\n$char = $z->ungetc($string)\n\ninflateSync\nUsage is\n\n$status = $z->inflateSync()\n\nTODO\n\ngetHeaderInfo\nUsage is\n\n$hdr  = $z->getHeaderInfo();\n@hdrs = $z->getHeaderInfo();\n\nThis method returns either a hash reference (in scalar context) or a list or hash references (in\narray context) that contains information about each of the header fields in the compressed data",
            "subsections": [
                {
                    "name": "stream",
                    "content": "tell\nUsage is\n\n$z->tell()\ntell $z\n\nReturns the uncompressed file offset.\n\neof\nUsage is\n\n$z->eof();\neof($z);\n\nReturns true if the end of the compressed input stream has been reached.\n\nseek\n$z->seek($position, $whence);\nseek($z, $position, $whence);\n\nProvides a sub-set of the \"seek\" functionality, with the restriction that it is only legal to\nseek forward in the input file/buffer. It is a fatal error to attempt to seek backward.\n\nNote that the implementation of \"seek\" in this module does not provide true random access to a\ncompressed file/buffer. It works by uncompressing data from the current offset in the\nfile/buffer until it reaches the uncompressed offset specified in the parameters to \"seek\". For\nvery small files this may be acceptable behaviour. For large files it may cause an unacceptable\ndelay.\n\nThe $whence parameter takes one the usual values, namely SEEKSET, SEEKCUR or SEEKEND.\n\nReturns 1 on success, 0 on failure.\n\nbinmode\nUsage is\n\n$z->binmode\nbinmode $z ;\n\nThis is a noop provided for completeness.\n\nopened\n$z->opened()\n\nReturns true if the object currently refers to a opened file/buffer.\n\nautoflush\nmy $prev = $z->autoflush()\nmy $prev = $z->autoflush(EXPR)\n\nIf the $z object is associated with a file or a filehandle, this method returns the current\nautoflush setting for the underlying filehandle. If \"EXPR\" is present, and is non-zero, it will\nenable flushing after every write/print operation.\n\nIf $z is associated with a buffer, this method has no effect and always returns \"undef\".\n\nNote that the special variable $| cannot be used to set or retrieve the autoflush setting.\n\ninputlinenumber\n$z->inputlinenumber()\n$z->inputlinenumber(EXPR)\n\nReturns the current uncompressed line number. If \"EXPR\" is present it has the effect of setting\nthe line number. Note that setting the line number does not change the current position within\nthe file/buffer being read.\n\nThe contents of $/ are used to determine what constitutes a line terminator.\n\nfileno\n$z->fileno()\nfileno($z)\n\nIf the $z object is associated with a file or a filehandle, \"fileno\" will return the underlying\nfile descriptor. Once the \"close\" method is called \"fileno\" will return \"undef\".\n\nIf the $z object is associated with a buffer, this method will return \"undef\".\n\nclose\n$z->close() ;\nclose $z ;\n\nCloses the output file/buffer.\n\nFor most versions of Perl this method will be automatically invoked if the\nIO::Uncompress::Inflate object is destroyed (either explicitly or by the variable with the\nreference to the object going out of scope). The exceptions are Perl versions 5.005 through\n5.00504 and 5.8.0. In these cases, the \"close\" method will be called automatically, but not\nuntil global destruction of all live objects when the program is terminating.\n\nTherefore, if you want your scripts to be able to run on all versions of Perl, you should call\n\"close\" explicitly and not rely on automatic closing.\n\nReturns true on success, otherwise 0.\n\nIf the \"AutoClose\" option has been enabled when the IO::Uncompress::Inflate object was created,\nand the object is associated with a file, the underlying file will also be closed.\n\nnextStream\nUsage is\n\nmy $status = $z->nextStream();\n\nSkips to the next compressed data stream in the input file/buffer. If a new compressed data\nstream is found, the eof marker will be cleared and $. will be reset to 0.\n\nReturns 1 if a new stream was found, 0 if none was found, and -1 if an error was encountered.\n\ntrailingData\nUsage is\n\nmy $data = $z->trailingData();\n\nReturns the data, if any, that is present immediately after the compressed data stream once\nuncompression is complete. It only makes sense to call this method once the end of the\ncompressed data stream has been encountered.\n\nThis option can be used when there is useful information immediately following the compressed\ndata stream, and you don't know the length of the compressed data stream.\n\nIf the input is a buffer, \"trailingData\" will return everything from the end of the compressed\ndata stream to the end of the buffer.\n\nIf the input is a filehandle, \"trailingData\" will return the data that is left in the filehandle\ninput buffer once the end of the compressed data stream has been reached. You can then use the\nfilehandle to read the rest of the input file.\n\nDon't bother using \"trailingData\" if the input is a filename.\n\nIf you know the length of the compressed data stream before you start uncompressing, you can\navoid having to use \"trailingData\" by setting the \"InputLength\" option in the constructor.\n"
                }
            ]
        },
        "Importing": {
            "content": "No symbolic constants are required by IO::Uncompress::Inflate at present.\n\n:all Imports \"inflate\" and $InflateError. Same as doing this\n\nuse IO::Uncompress::Inflate qw(inflate $InflateError) ;\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "",
            "subsections": [
                {
                    "name": "Working with Net::FTP",
                    "content": "See IO::Compress::FAQ\n"
                }
            ]
        },
        "SUPPORT": {
            "content": "General feedback/questions/bug reports should be sent to\n<https://github.com/pmqs/IO-Compress/issues> (preferred) or\n<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate,\nIO::Compress::RawDeflate, IO::Uncompress::RawInflate, IO::Compress::Bzip2,\nIO::Uncompress::Bunzip2, IO::Compress::Lzma, IO::Uncompress::UnLzma, IO::Compress::Xz,\nIO::Uncompress::UnXz, IO::Compress::Lzip, IO::Uncompress::UnLzip, IO::Compress::Lzop,\nIO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Compress::Zstd,\nIO::Uncompress::UnZstd, IO::Uncompress::AnyInflate, IO::Uncompress::AnyUncompress\n\nIO::Compress::FAQ\n\nFile::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib\n\nFor RFC 1950, 1951 and 1952 see <http://www.faqs.org/rfcs/rfc1950.html>,\n<http://www.faqs.org/rfcs/rfc1951.html> and <http://www.faqs.org/rfcs/rfc1952.html>\n\nThe *zlib* compression library was written by Jean-loup Gailly \"gzip@prep.ai.mit.edu\" and Mark\nAdler \"madler@alumni.caltech.edu\".\n\nThe primary site for the *zlib* compression library is <http://www.zlib.org>.\n\nThe primary site for gzip is <http://www.gzip.org>.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "This module was written by Paul Marquess, \"pmqs@cpan.org\".\n",
            "subsections": []
        },
        "MODIFICATION HISTORY": {
            "content": "See the Changes file.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright (c) 2005-2021 Paul Marquess. All rights reserved.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "IO::Uncompress::Inflate - Read RFC 1950 files/buffers",
    "flags": [],
    "examples": [
        "See IO::Compress::FAQ"
    ],
    "see_also": []
}