Archive-Zip-SimpleZip
view release on metacpan or search on metacpan
lib/Archive/Zip/StreamedUnzip.pm view on Meta::CPAN
$self->_stdPreq() or return 0 ;
*$self->{SZ}->eof;
}
sub _stdPreq
{
my $self = shift;
# TODO - fix me
return 1;
return _setError("Zip file closed")
if ! defined defined *$self->{SZ} || ! *$self->{Inner}{Open} ;
return _setError("member filehandle closed")
if ! *$self->{Open} ; #|| ! defined *$self->{SZ}{Raw};
return 0
if *$self->{SZ}{Error} ;
return 1;
}
sub _setError
{
$Archive::Zip::SimpleUnzip::StreamedUnzipError = $_[0] ;
return 0;
}
sub clearerr
{
my $self = shift;
return 0;
}
sub binmode { 1 }
# sub clearerr { $Archive::Zip::SimpleUnzip::StreamedUnzipError = '' }
*BINMODE = \&binmode;
# *SEEK = \&seek;
*READ = \&read;
*sysread = \&read;
*TELL = \&tell;
*READLINE = \&readline;
*EOF = \&eof;
*FILENO = \&fileno;
*CLOSE = \&close;
}
1;
__END__
=head1 NAME
Archive::Zip::StreamedUnzip - Read Zip Archives in streaming mode
=head1 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();
=head1 DESCRIPTION
Archive::Zip::StreamedUnzip is a module that allows reading of Zip archives in streaming mode.
This is useful if you are processing a zip coming directly off a socket without having to
read the complete file into memory and/or store it on disk. Similarly it can be handy when
woking with a pipelined command.
Working with a streamed zip file does have limitations, so
most of the time L<Archive::Zip::SimpleUnzip> and/or L<Archive::Zip> are a better choice of
module for reading file files.
For writing Zip archives, there is a companion module,
called L<Archive::Zip::SimpleZip>, that can create Zip archives.
=head2 Features
=over 5
=item * Read zip archive from a file, a filehandle or from an in-memory buffer.
=item * Perl Filehandle interface for reading a zip member.
=item * Supports deflate, store, bzip2, Zstandard (Zstd), Xz and lzma compression.
=item * Supports Zip64, so can read archves larger than 4Gig and/or have greater than 64K members.
=back
=head2 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
=over 5
=item * Input from a Filename
When StreamedUnzip is passed a string, it will read the zip archive from the
filename stored in the string.
=item * Input from a String
When StreamedUnzip is passed a string reference, like C<\$buffer>, it will
read the in-memory zip archive from that string.
=item * 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.
=back
See L</Options> for a list of the optional parameters that can be specified
when calling the constructor.
( run in 0.729 second using v1.01-cache-2.11-cpan-39bf76dae61 )