IO::Un...nflate(3perl)
π NAME π
IO::Uncompress::RawInflate β Read RFC 1951 files/buffers β¨
So this is IO::Uncompress::RawInflate(3perl), straight out of the Perl Programmers Reference Guide, and its whole entire job is reading RFC 1951 files and buffers. That's it, that's the gig. π
π SYNOPSIS π
use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
my $status = rawinflate $input => $output [,OPTS]
or die "rawinflate failed: $RawInflateError\n";
my $z = IO::Uncompress::RawInflate->new( $input [OPTS] )
or die "rawinflate failed: $RawInflateError\n";
$status = $z->read($buffer)
$status = $z->read($buffer, $length)
$status = $z->read($buffer, $length, $offset)
$line = $z->getline()
$char = $z->getc()
$char = $z->ungetc()
$char = $z->opened()
$status = $z->inflateSync()
$data = $z->trailingData()
$status = $z->nextStream()
$data = $z->getHeaderInfo()
$z->tell()
$z->seek($position, $whence)
$z->binmode()
$z->fileno()
$z->eof()
$z->close()
$RawInflateError ;
# IO::File mode
<$z>
read($z, $buffer);
read($z, $buffer, $length);
read($z, $buffer, $length, $offset);
tell($z)
seek($z, $position, $whence)
binmode($z)
fileno($z)
eof($z)
close($z)
πΈ DESCRIPTION πΈ
Okay so bestie, this module hands you a Perl interface that lets you read files and buffers that conform to RFC 1951. No cap.
And if you're trying to go the other way β like, writing RFC 1951 files/buffers instead of reading them β you want the companion module IO::Compress::RawDeflate. That's its whole thing. π«Ά
π¦ Functional Interface π¦
There's a top-level function called rawinflate that does "one-shot" uncompression between buffers and/or files. It's giving extremely low-effort, extremely effective. π
But if you want finer control over the uncompression process, go read the "OO Interface" section instead.
use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
rawinflate $input_filename_or_reference => $output_filename_or_reference [,OPTS]
or die "rawinflate failed: $RawInflateError\n";
Heads up: the functional interface needs Perl5.005 or better. Yes, 5.005. Ancient. Iconic of it honestly.
β rawinflate $input_filename_or_reference => $output_filename_or_reference [, OPTS] β
rawinflate expects at least two parameters β $input_filename_or_reference and $output_filename_or_reference β plus zero or more optional parameters (peep the "Optional Parameters" section for those π).
π The $input_filename_or_reference parameter π
The $input_filename_or_reference parameter is what defines where your compressed data is coming from. It can be any one of these little guys:
A filename
If $input_filename_or_reference is a simple scalar, it's assumed to be a filename. That file gets opened for reading, and the input data gets read out of it.
A filehandle
If $input_filename_or_reference is a filehandle, the input data gets read from it. And plot twist β the string '-' can be used as an alias for standard input. π
A scalar reference
If $input_filename_or_reference is a scalar reference, the input data is read from $$input_filename_or_reference.
An array reference
If $input_filename_or_reference is an array reference, every single element in that array has to be a filename. The input data gets read from each file in turn. And the complete array gets walked to make sure it only contains valid filenames before any data is uncompressed β so it checks first, decompresses later. Organized. π
An Input FileGlob string
If $input_filename_or_reference is a string delimited by the characters < and >, rawinflate assumes it's an input fileglob string. The input is the list of files that match the fileglob. See File::GlobMapper for more details.
And if$input_filename_or_referenceis any other type?undefgets returned. That's it, that's the whole response. π
π¦ The $output_filename_or_reference parameter π¦
The $output_filename_or_reference parameter controls where the uncompressed data is headed. It can take one of these forms:
A filename
If $output_filename_or_reference is a simple scalar, it's assumed to be a filename. That file gets opened for writing, and the uncompressed data gets written to it.
A filehandle
If $output_filename_or_reference is a filehandle, the uncompressed data gets written to it. And yes β the string '-' can be used as an alias for standard output. π«Ά
A scalar reference
If $output_filename_or_reference is a scalar reference, the uncompressed data gets stored in $$output_filename_or_reference.
An Array Reference
If $output_filename_or_reference is an array reference, the uncompressed data gets pushed onto the array.
An Output FileGlob
If $output_filename_or_reference is a string delimited by the characters < and >, rawinflate assumes it's an output fileglob string. The output is the list of files that match the fileglob.
When $output_filename_or_reference is an fileglob string, $input_filename_or_reference must also be a fileglob string. Anything else is an error. Periodt.
See File::GlobMapper for more details.
And if$output_filename_or_referenceis any other type,undefgets returned. Same energy as before. π
β¨ Notes β¨
When $input_filename_or_reference maps to multiple compressed files/buffers, and $output_filename_or_reference is a single file/buffer, then after uncompression, $output_filename_or_reference will contain a concatenation of all the uncompressed data from each of the input files/buffers. All of it. Every last bit. Slay. π
π Optional Parameters π
The optional parameters for the one-shot function rawinflate are (for the most part) identical to the ones used with the OO interface defined in the "Constructor Options" section. The exceptions are listed below. So like, mostly the same, but here's the receipts. π§Ύ
AutoClose => 0|1β this option applies to any input or output data streams torawinflatethat are filehandles.
If AutoClose is specified and the value is true, it results in all input and/or output filehandles being closed once rawinflate has completed.
This parameter defaults to 0.
BinModeOut => 0|1β this option is now a no-op. All files will be written in binmode. Nothing to see here bestie, move along. πΆββοΈAppend => 0|1β the behaviour of this option depends on the type of output data stream. Let's break it down:- A Buffer β if
Appendis enabled, all uncompressed data gets appended to the end of the output buffer. Otherwise the output buffer gets cleared before any uncompressed data is written to it. - A Filename β if
Appendis enabled, the file gets opened in append mode. Otherwise the contents of the file (if any) get truncated before any uncompressed data is written to it. - A Filehandle β if
Appendis enabled, the filehandle gets positioned to the end of the file via a call toseekbefore any uncompressed data is written to it. Otherwise the file pointer doesn't move at all.
- A Buffer β if
When Append is specified and set to true, it appends all uncompressed data to the output data stream.
So when the output is a filehandle, it carries out a seek to the eof before writing any uncompressed data. If the output is a filename, it gets opened for appending. If the output is a buffer, all uncompressed data gets appended to the existing buffer.
Conversely, when Append is not specified β or it's present and set to false β it operates like this: when the output is a filename, it truncates the contents of the file before writing any uncompressed data. If the output is a filehandle, its position isn't changed. If the output is a buffer, it gets wiped before any uncompressed data is output.
Defaults to 0.
MultiStream => 0|1β this option is a no-op. That's the whole description. πTrailingData => $scalarβ returns the data, if any, that's present immediately after the compressed data stream once uncompression is complete.
This option is your girl when there's useful information sitting immediately after the compressed data stream, and you don't know the length of the compressed data stream.
If the input is a buffer, trailingData returns everything from the end of the compressed data stream to the end of the buffer.
If the input is a filehandle, trailingData returns the data left in the filehandle input buffer once the end of the compressed data stream has been reached. You can then use the filehandle to read the rest of the input file. Chef's kiss. π©βπ³π
Don't bother using trailingData if the input is a filename.
And ngl, if you already know the length of the compressed data stream before you start uncompressing, you can avoid needing trailingData at all by setting the InputLength option.
π OneShot Examples π
To read the contents of the file file1.txt.1951 and write the uncompressed data to the file file1.txt:
use strict ;
use warnings ;
use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
my $input = "file1.txt.1951";
my $output = "file1.txt";
rawinflate $input => $output
or die "rawinflate failed: $RawInflateError\n";
To read from an existing Perl filehandle, $input, and write the uncompressed data to a buffer, $buffer:
use strict ;
use warnings ;
use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
use IO::File ;
my $input = IO::File->new( "<file1.txt.1951" )
or die "Cannot open 'file1.txt.1951': $!\n" ;
my $buffer ;
rawinflate $input => \$buffer
or die "rawinflate failed: $RawInflateError\n";
To uncompress all files in the directory /my/home that match *.txt.1951 and store the compressed data in the same directory:
use strict ;
use warnings ;
use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
rawinflate '</my/home/*.txt.1951>' => '</my/home/#1.txt>'
or die "rawinflate failed: $RawInflateError\n";
and if you want to compress each file one at a time, this will do the trick:
use strict ;
use warnings ;
use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
for my $input ( glob "/my/home/*.txt.1951" )
{
my $output = $input;
$output =~ s/.1951// ;
rawinflate $input => $output
or die "Error compressing '$input': $RawInflateError\n";
}
π¦ OO Interface π¦
β¨ Constructor β¨
okay so bestie, here's the whole vibe of the constructor for IO::Uncompress::RawInflate:
my $z = IO::Uncompress::RawInflate->new( $input [OPTS] )
or die "IO::Uncompress::RawInflate failed: $RawInflateError\n";
it takes ONE mandatory param, $input (she's explained right below π
), plus zero or more OPTS, and those live in "Constructor Options".
She hands you back an IO::Uncompress::RawInflate object when it works, and undef when it doesn't. if it flops, the variable $RawInflateError is holding the error message for you β like a little note passed in class π
now, if you're on Perl 5.005 or newer, the object $z you get back can be used exactly like an IO::File filehandle. which means every normal input file operation can just be done with $z. for example, to read a line out of a compressed file/buffer you can do either of these:
$line = $z->getline();
$line = <$z>;
here's a lil example of using the OO interface to read the compressed file myfile.1951 and write its contents out to stdout:
my $filename = "myfile.1951";
my $z = IO::Uncompress::RawInflate->new($filename)
or die "IO::Uncompress::RawInflate failed: $RawInflateError\n";
while (<$z>) {
print $_;
}
$z->close();
peep "EXAMPLES" for more examples if you're hungry for more π
that mandatory $input param is what tells the module where the compressed data is coming from. and she can show up in one of three forms:
π A filename
if $input is a scalar, it gets treated as a filename. that file gets opened for reading and the compressed data is read out of it. simple, iconic, no notes.
π A filehandle
if $input is a filehandle, the compressed data gets read from it. and the string '-' can be used as an alias for standard input, which is lowkey so convenient.
πͺ A scalar reference
if $input is a scalar reference, the compressed data gets read from $$input. yes bestie, we're double-dereferencing, it's giving very perl.
π Constructor Options π
first things first: all the option names below are case insensitive and can optionally have a '-' in front. so every single one of these is valid:
-AutoClose
-autoclose
AUTOCLOSE
autoclose
OPTS is a combination of the following options:
AutoClose => 0|1β this one's only valid when$inputis a filehandle. if you set it and the value is true, the file gets closed once either theclosemethod is called OR theIO::Uncompress::RawInflateobject gets destroyed. defaults to0.MultiStream => 0|1β lets multiple concatenated compressed streams get treated like one single compressed stream. decompression stops as soon as one of these happens: you hit the end of the file/buffer, an error shows up (premature eof, corrupt compressed data β the usual suspects π), or the end of a stream is not immediately followed by the start of another stream. defaults to0.Prime => $stringβ un-compresses the contents of$stringbefore it even touches the input file/buffer. super handy when the compressed data is embedded inside some other file/data structure and there's just no way to figure out where the compressed data begins without reading the first few bytes first. in that case you can prime the uncompression with those bytes using this. it's giving "unlocking the door before you walk in" ποΈTransparent => 0|1β if this is set and the input file/buffer is NOT compressed data, the module will let you read it anyway. also, if the input file/buffer DOES contain compressed data and there's non-compressed data immediately after it, turning this on makes the module treat the whole file/buffer as one single data stream. defaults to1.BlockSize => $numβ when reading the compressed input data,IO::Uncompress::RawInflatereads it in blocks of$numbytes. defaults to4096.InputLength => $sizeβ when this one is present, it limits how many compressed bytes get read from the input file/buffer to$size. this is the move when there's useful data sitting right after the compressed data stream and you already know exactly how long the compressed data stream is. mostly used when reading from a filehandle β and in that case the file pointer gets left pointing at the first byte directly after the compressed data stream. defaults to off.Append => 0|1β controls what thereadmethod does with uncompressed data. set it to1and all the uncompressed data gets appended to the output parameter ofread. set it to0and the contents of the output parameter ofreadget overwritten by the uncompressed data. defaults to0.Strict => 0|1β bestie this one is a no-op. it literally does nothing. do with that information what you will π
πΈ Methods πΈ
π
read
Bestie, the usage goes like this:
$status = $z->read($buffer)
So what's happening: it reads a block of compressed data (the size of that block is decided by the Buffer option you set in the constructor), uncompresses it, and writes whatever uncompressed data falls out into $buffer. Now listen β if you set the Append parameter in the constructor, the uncompressed data gets appended onto the $buffer parameter. Otherwise $buffer gets fully overwritten. No in-between.
It returns the number of uncompressed bytes written to $buffer, zero if eof, or a negative number on error. Slay.
π
read (round two β the exact-length one)
Usage:
$status = $z->read($buffer, $length)
$status = $z->read($buffer, $length, $offset)
$status = read($z, $buffer, $length)
$status = read($z, $buffer, $length, $offset)
This one tries to read $length bytes of uncompressed data into $buffer.
The big glow-up difference between this form of the read method and the previous one is that this one will attempt to return exactly $length bytes. The only times it won't is if it hits end-of-file or an IO error is encountered. That's it, that's the whole list.
Returns the number of uncompressed bytes written to $buffer, zero if eof, or a negative number on error.
β¨ getline
Usage:
$line = $z->getline()
$line = <$z>
Reads a single line. Periodt.
This method fully supports using the $/ variable (or $INPUT_RECORD_SEPARATOR, or $RS when English is in use) to decide what counts as an end of line. Paragraph mode, record mode and file slurp mode are all supported. All of them. The whole squad. π«Ά
π getc
Usage:
$char = $z->getc()
Read a single character. One. Character. Tiny little guy.
π¦ ungetc
Usage:
$char = $z->ungetc($string)
π inflateSync
Usage:
$status = $z->inflateSync()
TODO. Yeah, that's genuinely all it says bestie, the docs said TODO and I'm not about to make stuff up. π
πΈ getHeaderInfo
Usage:
$hdr = $z->getHeaderInfo();
@hdrs = $z->getHeaderInfo();
This method returns either a hash reference (in scalar context) or a list of hash references (in array context) that contains information about each of the header fields in the compressed data stream(s). Info about every header field, per stream. Iconic.
π tell
Usage:
$z->tell()
tell $z
Returns the uncompressed file offset.
β eof
Usage:
$z->eof();
eof($z);
Returns true if the end of the compressed input stream has been reached.
π₯ seek
$z->seek($position, $whence);
seek($z, $position, $whence);
Gives you a sub-set of the seek functionality, with the restriction that it is only legal to seek forward in the input file/buffer. Attempting to seek backward is a fatal error. Like, it will not play with you.
Heads up: the implementation ofseekin this module does not provide true random access to a compressed file/buffer. What it actually does is uncompress data from the current offset in the file/buffer until it reaches the uncompressed offset you specified in the parameters toseek. For very small files this may be acceptable behaviour. For large files it may cause an unacceptable delay. Soβ¦ small files, fine. Big files, pack a snack. π
The $whence parameter takes one of the usual values, namely SEEK_SET, SEEK_CUR or SEEK_END.
Returns 1 on success, 0 on failure.
π§ binmode
Usage:
$z->binmode
binmode $z ;
This is a noop provided for completeness. Nothing happens. It's just there to be polite. π
π opened
$z->opened()
Returns true if the object currently refers to an opened file/buffer.
π autoflush
my $prev = $z->autoflush()
my $prev = $z->autoflush(EXPR)
If the $z object is associated with a file or a filehandle, this method returns the current autoflush setting for the underlying filehandle. If EXPR is present, and is non-zero, it will enable flushing after every write/print operation.
If $z is associated with a buffer, this method has no effect and always returns undef.
Note that the special variable $| cannot be used to set or retrieve the autoflush setting. She does not work here, bestie.
π input_line_number
$z->input_line_number()
$z->input_line_number(EXPR)
Returns the current uncompressed line number. If EXPR is present it has the effect of setting the line number. Note that setting the line number does not change the current position within the file/buffer being read. It's purely cosmetic, like changing your profile pic.
The contents of $/ are used to determine what constitutes a line terminator.
πΈ fileno
$z->fileno()
fileno($z)
If the $z object is associated with a file or a filehandle, fileno will return the underlying file descriptor. Once the close method is called, fileno will return undef.
If the $z object is associated with a buffer, this method will return undef. F in the chat. π«Ά
π
close
$z->close() ;
close $z ;
Closes the output file/buffer.
For most versions of Perl this method will be automatically invoked if the IO::Uncompress::RawInflate object is destroyed (either explicitly, or by the variable with the reference to the object going out of scope). The exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In those cases, the close method will be called automatically, but not until global destruction of all live objects when the program is terminating. Yikes. π
So if you want your scripts to be able to run on all versions of Perl, you should call close explicitly and not rely on automatic closing. Do it yourself, it's not that deep.
Returns true on success, otherwise 0.
If the AutoClose option has been enabled when the IO::Uncompress::RawInflate object was created, and the object is associated with a file, the underlying file will also be closed.
β nextStream
Usage:
my $status = $z->nextStream();
Skips to the next compressed data stream in the input file/buffer. If a new compressed data stream is found, the eof marker will be cleared and $. will be reset to 0.
Returns 1 if a new stream was found, 0 if none was found, and -1 if an error was encountered.
π¦ trailingData
Usage:
my $data = $z->trailingData();
Returns the data, if any, that is present immediately after the compressed data stream once uncompression is complete. It only makes sense to call this method once the end of the compressed data stream has been encountered. Timing is everything, bestie.
This option can be used when there is useful information immediately following the compressed data stream, and you don't know the length of the compressed data stream.
If the input is a buffer, trailingData will return everything from the end of the compressed data stream to the end of the buffer.
If the input is a filehandle, trailingData will return the data that is left in the filehandle input buffer once the end of the compressed data stream has been reached. You can then use the filehandle to read the rest of the input file.
Don't bother using trailingData if the input is a filename. Just don't.
If you know the length of the compressed data stream before you start uncompressing, you can avoid having to use trailingData by setting the InputLength option in the constructor. Planner girlies stay winning. π
π Importing π
No symbolic constants are required by IO::Uncompress::RawInflate at present.
:allβ Importsrawinflateand$RawInflateError. Same as doing this:
use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
β¨ EXAMPLES β¨
π Working with Net::FTP
See IO::Compress::FAQ.
(That's the whole section, bestie. It's a redirect and we respect it. π )
π SUPPORT π
General feedback/questions/bug reports should be sent to <https://github.com/pmqs/IO-Compress/issues> (preferred) or <https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
π SEE ALSO π
Compress::Zlib,IO::Compress::Gzip,IO::Uncompress::GunzipIO::Compress::Deflate,IO::Uncompress::InflateIO::Compress::RawDeflate,IO::Compress::Bzip2,IO::Uncompress::Bunzip2IO::Compress::Lzma,IO::Uncompress::UnLzma,IO::Compress::Xz,IO::Uncompress::UnXzIO::Compress::Lzip,IO::Uncompress::UnLzipIO::Compress::Lzop,IO::Uncompress::UnLzopIO::Compress::Lzf,IO::Uncompress::UnLzfIO::Compress::Zstd,IO::Uncompress::UnZstdIO::Uncompress::AnyInflate,IO::Uncompress::AnyUncompressIO::Compress::FAQFile::GlobMapper,Archive::Zip,Archive::Tar,IO::Zlib
For RFC 1950, 1951 and 1952 see <https://datatracker.ietf.org/doc/html/rfc1950>, <https://datatracker.ietf.org/doc/html/rfc1951> and <https://datatracker.ietf.org/doc/html/rfc1952>.
The zlib compression library was written by Jean-loup Gailly gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
The primary site for the zlib compression library is <http://www.zlib.org>.
The primary site for the zlib-ng compression library is <https://github.com/zlib-ng/zlib-ng>.
The primary site for gzip is <http://www.gzip.org>.
π AUTHOR π
This module was written by Paul Marquess, pmqs@cpan.org. Legend behaviour fr fr. π«Ά
π¦ MODIFICATION HISTORY π¦
See the Changes file.
π COPYRIGHT AND LICENSE π
Copyright (c) 2005-2026 Paul Marquess. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
And that's a wrap on part 3, my love β this page is from Perl v5.44.0, dated 2026-10-17, and it goes out to every single one of you reading a manpage at 2am. You understood all of it, which is genuinely main character energy. Bye bestieee π
β¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms