Archive...medUnzip(3)
π NAME π
okay so Archive::Zip::StreamedUnzip β bestie, this is the module that reads Zip archives in streaming mode. periodt β¨
π SYNOPSIS π
use Archive::Zip::StreamedUnzip qw($StreamedUnzipError) ;
my $z = Archive::Zip::StreamedUnzip->new('my.zip')
or die "Cannot open zip file: $StreamedUnzipError\n" ;
# Iterate through a zip archive
while (my $member = $z->next)
{
print $member->name() . "\n" ;
}
# Archive::Zip::StreamedUnzip::Member
my $name = $member->name();
my $content = $member->content();
my $comment = $member->comment();
# open a filehandle to read from a zip member
$fh = $member->open('mydata1.txt');
# read blocks of data
read($fh, $buffer, 1234) ;
# or a line at a time
$line = <$fh> ;
close $fh;
$z->close();
πΈ DESCRIPTION πΈ
Archive::Zip::StreamedUnzip is a module that allows reading of Zip archives in streaming mode. The way that this is so useful is: if you're processing a zip that's coming directly off a socket, you don't have to read the complete file into memory and/or store it on disk. Iconic. Similarly it can be handy when woking with a pipelined command.
π«Ά heads up bestie β working with a streamed zip file does have limitations, so most of the timeArchive::Zip::SimpleUnzipand/orArchive::Zipare a better choice of module for reading file files.
For writing Zip archives, there's a companion module, called Archive::Zip::SimpleZip, that can create Zip archives. π
β¨ Features β¨
- Read zip archive from a file, a filehandle or from an in-memory buffer. πΎ
- Perl Filehandle interface for reading a zip member.
- Supports deflate, store, bzip2, Zstandard (Zstd), Xz and lzma compression. π₯
- Supports Zip64, so it can read archves larger than 4Gig and/or have greater than 64K members. π
π§ Constructor π§
$z = Archive::Zip::StreamedUnzip->new('myzipfile.zip' [, OPTIONS]) ;
$z = Archive::Zip::StreamedUnzip->new(\$buffer [, OPTIONS]) ;
$z = Archive::Zip::StreamedUnzip->new($filehandle [, OPTIONS]) ;
The constructor takes one mandatory parameter along with zero or more optional parameters.
The mandatory parameter controls where the zip archive is read from. This can be any one of the following π
- Input from a Filename β When StreamedUnzip is passed a string, it will read the zip archive from the filename stored in the string.
- Input from a String β When StreamedUnzip is passed a string reference, like
"\$buffer", it will read the in-memory zip archive from that string. - Input from a Filehandle β When StreamedUnzip is passed a filehandle, it will read the zip archive from that filehandle. Note the filehandle must be seekable. β οΈ
See "Options" for a list of the optional parameters that can be specified when calling the constructor.
π Options π
None yet.
ngl the options section is giving minimalist era π zero options, we love that for us
π Methods π
$z->next()β Returns the next member from the zip archive as aArchive::Zip::StreamedUnzip::Memberobject. See "Archive::Zip::StreamedUnzip::Member".
Standard usage is
use Archive::Zip::StreamedUnzip qw($StreamedUnzipError) ;
my $match = 'hello';
my $zipfile = 'my.zip';
my $z = Archive::Zip::StreamedUnzip->new($zipfile)
or die "Cannot open zip file: $StreamedUnzipError\n" ;
while (my $member = $z->next())
{
my $name = $member->name();
my $fh = $member->open();
while (<$fh>)
{
my $offset =
print "$name, line $.\n" if /$match/;
}
}
$z->close()β Closes the zip file. bye bestie π¦
π¦ Archive::Zip::StreamedUnzip::Member π¦
The "next" method returns a member object of type Archive::Zip::StreamedUnzip::Member that has the following methods. π
$string = $m->name()β Returns the name of the member.$data = $m->content()β Returns the uncompressed content.$fh = $m->open()β Returns a filehandle that can be used to read the uncompressed content.
π Examples π
β Iterate through a Zip file β
use Archive::Zip::StreamedUnzip qw($StreamedUnzipError) ;
my $zipfile = 'my.zip';
my $z = Archive::Zip::StreamedUnzip->new($zipfile)
or die "Cannot open zip file: $StreamedUnzipError\n" ;
while (my $member = $z->next())
{
print "$member->name()\n";
}
π Filehandle interface π
Here is a simple grep, that walks through a zip file and prints matching strings. iykyk π
use Archive::Zip::StreamedUnzip qw($StreamedUnzipError) ;
my $match = 'hello;
my $zipfile = 'my.zip';
my $z = Archive::Zip::StreamedUnzip->new($zipfile)
or die "Cannot open zip file: $StreamedUnzipError\n" ;
while (my $member = $z->next())
{
my $name = $member->name();
my $fh = $member->open();
while (<$fh>)
{
my $offset =
print "$name, line $.\n" if /$match/;
}
}
π§ Nested Zip π§
Here is a script that will list the contents of a zip file along with any zip files that are embedded in it. In fact it will work with any level of nesting. π€― it's giving inception fr fr
sub walk
{
my $unzip = shift ;
my $depth = shift // 1;
while (my $member = $unzip->next())
{
my $name = $unzip->name();
print ' ' x $depth . "$name\n" ;
if ($name =~ /\.zip$/i)
{
my $fh = $member->open();
my $newunzip = Archive::Zip::StreamedUnzip->new($fh);
walk($newunzip, $depth + 1);
}
}
}
my $unzip = Archive::Zip::StreamedUnzip->new($zipfile)
or die "Cannot open '$zipfile': $StreamedUnzipError";
print "$zipfile\n" ;
walk($unzip) ;
π Zip File Interoperability π
The intention is to be interoperable with zip archives created by other programs, like pkzip or WinZip, but the majority of testing carried out used the Info-Zip zip/unzip <http://www.info-zip.org/> programs running on Linux. π§
This doesn't necessarily mean that there is no interoperability with other zip programs like pkzip and WinZip β it just means that I haven't tested them. Please report any issues you find. π
ποΈ Compression Methods Supported ποΈ
The following compression methods are supported π
deflate (8)β This is the most common compression used in zip archives. π₯store (0)β This is used when no compression has been carried out.bzip2 (12)β Only if the "IO-Compress-Bzip2" module is available.lzma (14)β Only if the "IO-Compress-Lzma" module is available.Xz (95)β To read Xz content, the module"IO::Uncompress::UnXz"must be installed.Zstandard (93)β To read Zstandard content, the module"IO::Uncompress::UnZstd"must be installed.
π Zip64 Support π
This modules supports Zip64, so it can read archves larger than 4Gig and/or have greater than 64K members. π
π Limitations π
The following features are not currently supported. sobbing
- Compression methods not listed in "Compression Methods Supported"
- Multi-Volume Archives
- Encrypted Archives
β οΈ bestie if you need any of these three, this is not the module for you and that's okay π«Ά
π«Ά SUPPORT π«Ά
General feedback/questions/bug reports should be sent to <https://github.com/pmqs/Archive-Zip-SimpleZip/issues> (preferred) or <https://rt.cpan.org/Public/Dist/Display.html?Name=Archive-Zip-SimpleZip>.
π SEE ALSO π
Archive::Zip::SimpleUnzip, Archive::Zip::SimpleZip, Archive::Zip, IO::Compress::Zip, IO::Uncompress::UnZip
π AUTHOR π
This module was written by Paul Marquess, pmqs@cpan.org. king behavior π
π MODIFICATION HISTORY π
See the Changes file.
π COPYRIGHT AND LICENSE π
Copyright (c) 2019-2024 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.
okay bestie that's the whole page π this one shipped with perl v5.42.0 on 2025-07-25 β go read some zips, you've got this πβ¨π¦
π¦ where this page comes from
- fedora 43: perl-Archive-Zip-SimpleZip 1.002-3.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms