Archive...pleUnzip(3)
π¦ Archive::Zip::SimpleUnzip(3) β Read Zip Archives π
okay bestie so this is Archive::Zip::SimpleUnzip(3) β it lives in User Contributed Perl Documentation, section 3 of the manual (the "here's a library function" section, iykyk). And fr fr, the whole vibe of this page is: you have a zip file. you want to read it. this module is the way. π«Ά
β¨ NAME β¨
Archive::Zip::SimpleUnzip β Read Zip Archives. That's it, that's the whole name. Short, sweet, iconic. π
π SYNOPSIS π
here's the whole thing in action, no notes:
use Archive::Zip::SimpleUnzip qw($SimpleUnzipError) ;
my $z = Archive::Zip::SimpleUnzip->NEW('my.zip')
or die "Cannot open zip file: $SimpleUnzipError\n" ;
# How many members in the archive?
my $members = scalar $z->names();
# Get the names of all the members in a zip archive
my @names = $z->names();
# Test member existence
if ($z->exists('abc.txt'))
{
...
}
# Extract member to filesystem
$z->extract('member') ;
$z->extract('member', 'outfile') ;
# Read the zip comment
my $comment = $zip->comment();
# Select a member by name
my $member = $z->member('abc.txt');
my $name = $member->name();
my $content = $member->content();
my $comment = $member->comment();
# Iterate through a zip archive
while (my $member = $z->next)
{
print $member->name() . "\n" ;
$member->extract();
$member->extract("outfile");
}
# Archive::Zip::SimpleUnzip::Member
# 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();
look at that. one module, so many moves. main character energy honestly. π
πΈ DESCRIPTION πΈ
Archive::Zip::SimpleUnzip is a module that lets you read Zip archives. That's its whole job and it does it gorgeously.
Now, for writing Zip archives, there's a companion module called Archive::Zip::SimpleZip that can create Zip archives. dynamic duo. platonic soulmates. β¨
π Features π
- Read zip archive from a file, a filehandle or from an in-memory buffer.
careful bestie β the code assumes that the zip archive is being read from a seekable file/filehandle/buffer. no seek, no service. π
- Perl Filehandle interface for reading a zip member. so you can just
< $fh >like it's any other file, obsessed. - Supports
deflate,store,bzip2,Zstandard(Zstd),Xzandlzmacompression. a whole buffet. π - Supports Zip64, so it can read archves larger than 4Gig and/or have greater than 64K members. yes it says "archves", we're leaving it, it's part of the charm.
π§ Constructor π§
$z = Archive::Zip::SimpleUnzip->new('myzipfile.zip' [, OPTIONS]) ;
$z = Archive::Zip::SimpleUnzip->new(\$buffer [, OPTIONS]) ;
$z = Archive::Zip::SimpleUnzip->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. It can be any one of these:
- Input from a Filename
When SimpleUnzip is passed a string, it will read the zip archive from the filename stored in the string.
- Input from a String
When SimpleUnzip is passed a string reference, like \$buffer, it will read the in-memory zip archive from that string.
- Input from a Filehandle
When SimpleUnzip is passed a filehandle, it will read the zip archive from that filehandle. Note the filehandle must be seekable. (yes, again. it matters. π)
See "Options" for a list of the optional parameters that can be specified when calling the constructor.
π Options π
-FilesOnly => 1|0β when true, ignore members in the zip archive that are directories. Turning this on will change the behaviour of thenames,nextandexistsmethods. Default is false. so if you're like "why isexistsacting different" β babe you turned on FilesOnly. π
π Methods π
$buffer = $z->content($member)β Returns the uncompressed data stored in$member. Returnsundefif the member does not exist. (not an error, just vibes. it's gone.)$buffer = $z->extract($member [, $outfile])β Uncompresses the data stored in$memberand writes it to the filesystem. By default the filename used is the member name. If the optional parameter$outfileis specified, the payload is written to that file instead. β¨$string = $z->comment()β Returns the comment, if any, associated with the zip archive.$z->exists('name')β Tests for the existence of membernamein the zip archive. returns true/false, simple as.$count = $z->names()@names = $z->names()β In scalar context returns the number of members in the Zip archive. In array context returns a list of the names of the members in the Zip archive. one method, two moods. π$z->next()β Returns the next member from the zip archive as aArchive::Zip::SimpleUnzip::Memberobject. See "Archive::Zip::SimpleUnzip::Member".
Standard usage is
use Archive::Zip::SimpleUnzip qw($SimpleUnzipError) ;
my $match = 'hello';
my $zipfile = 'my.zip';
my $z = Archive::Zip::SimpleUnzip->new($zipfile)
or die "Cannot open zip file: $SimpleUnzipError\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 archive. say goodbye, be polite. π«Ά
π Archive::Zip::SimpleUnzip::Member π
The next method from Archive::Zip::SimpleUnzip returns a member object of type Archive::Zip::SimpleUnzip::Member that has the following methods. it's giving "little object, big responsibilities".
$string = $m->name()β Returns the name of the member.$string = $m->comment()β Returns the member comment.$data = $m->content()β Returns the uncompressed content. π$buffer = $m->extract()/$buffer = $m->extract($outfile)β Uncompresses the data stored in the current member and writes to the filesystem. By default the filename used is the member name. If the optional parameter$outfileis specified, the payload is written to that file instead.
ngl the original pod formatting glitched out on this one (=itemgot eaten mid-line), but it's justextract()andextract($outfile). same energy as the archive-level one. π
$fh = $m->open()β Returns a filehandle that can be used to read the uncompressed content.$bool = $m->isDirectory()β Returns true if the member is a directory. Otherwise returns false.$bool = $m->isFile()β Returns true if the member is standard file. Otherwise returns false.
and that's where part 1 lands bestie β the examples, interoperability tea, limitations and the rest are still coming. π¦
π COPYRIGHT AND LICENSE π
Okay bestie, legal moment, but make it cute. Copyright (c) 2018-2024 Paul Marquess. All rights reserved. π
So here's the vibe: this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. That's it, that's the whole deal. Slay. π
Not me actually reading the license instead of just scrolling past it β but fr fr, read it, it's short and it's giving generous. π«Ά
And that's a wrap on the whole page, bestie!! β¨ This lil' rewrite is serving perl v5.42.0, dated 2025-07-25, straight from Archive...pleUnzip(3) β go forth and unzip things, you absolute icon. ππ¦ periodt. π
π¦ 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