Archive...medUnzip(3)

πŸ“¦
version 1.002 Β· 4 versions
, in fedora 43

πŸ’– 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 time Archive::Zip::SimpleUnzip and/or Archive::Zip are 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 a Archive::Zip::StreamedUnzip::Member object. 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 (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