"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bin/streamzip" between
IO-Compress-2.100.tar.gz and IO-Compress-2.101.tar.gz

About: IO-Compress is a Perl interface to the zlib compression library (contains Compress-Zlib, IO-Compress-Zlib, IO-Compress-Bzip2, IO-Compress-Base).

streamzip  (IO-Compress-2.100):streamzip  (IO-Compress-2.101)
#!/usr/bin/perl #!/usr/bin/perl
# Streaming zip # Streaming zip
use strict; use strict;
use warnings; use warnings;
use IO::Compress::Zip qw(zip use IO::Compress::Zip qw(zip
ZIP_CM_STORE ZIP_CM_STORE
ZIP_CM_DEFLATE ZIP_CM_DEFLATE
ZIP_CM_BZIP2 ZIP_CM_BZIP2 ) ;
ZIP_CM_LZMA );
use Getopt::Long; use Getopt::Long;
my $VERSION = '1.001'; my $VERSION = '1.002';
my $compression_method = ZIP_CM_DEFLATE; my $compression_method = ZIP_CM_DEFLATE;
my $stream = 0; my $stream = 0;
my $zipfile = '-'; my $zipfile = '-';
my $memberName = '-' ; my $memberName = '-' ;
my $zip64 = 0 ; my $zip64 = 0 ;
my $level ;
GetOptions("zip64" => \$zip64, GetOptions("zip64" => \$zip64,
"method=s" => \&lookupMethod, "method=s" => \&lookupMethod,
"0" => sub { $level = 0 },
"1" => sub { $level = 1 },
"2" => sub { $level = 2 },
"3" => sub { $level = 3 },
"4" => sub { $level = 4 },
"5" => sub { $level = 5 },
"6" => sub { $level = 6 },
"7" => sub { $level = 7 },
"8" => sub { $level = 8 },
"9" => sub { $level = 9 },
"stream" => \$stream, "stream" => \$stream,
"zipfile=s" => \$zipfile, "zipfile=s" => \$zipfile,
"member-name=s" => \$memberName, "member-name=s" => \$memberName,
'version' => sub { print "$VERSION\n"; exit 0 }, 'version' => sub { print "$VERSION\n"; exit 0 },
'help' => \&Usage, 'help' => \&Usage,
) )
or Usage(); or Usage();
Usage() Usage()
if @ARGV; if @ARGV;
my @extraOpts = ();
if ($compression_method == ZIP_CM_DEFLATE && defined $level)
{
push @extraOpts, (Level => $level)
}
zip '-' => $zipfile, zip '-' => $zipfile,
Name => $memberName, Name => $memberName,
Zip64 => $zip64, Zip64 => $zip64,
Method => $compression_method, Method => $compression_method,
Stream => $stream Stream => $stream,
@extraOpts
or die "Error creating zip file '$zipfile': $\n" ; or die "Error creating zip file '$zipfile': $\n" ;
exit 0; exit 0;
sub lookupMethod sub lookupMethod
{ {
my $name = shift; my $name = shift;
my $value = shift ; my $value = shift ;
my %valid = ( store => ZIP_CM_STORE, my %valid = ( store => ZIP_CM_STORE,
deflate => ZIP_CM_DEFLATE, deflate => ZIP_CM_DEFLATE,
bzip2 => ZIP_CM_BZIP2, bzip2 => ZIP_CM_BZIP2,
lzma => ZIP_CM_LZMA, lzma => 14,
xz => 95,
zstd => 93,
); );
my $method = $valid{ lc $value }; my $method = $valid{ lc $value };
Usage("Unknown method '$value'") Usage("Unknown method '$value'")
if ! defined $method; if ! defined $method;
# If LZMA was rquested, check that it is available installModule("Lzma")
if ($method == ZIP_CM_LZMA) if $method == 14 ;
{
eval ' use IO::Compress::Adapter::Lzma'; installModule("Xz")
die "Method 'LZMA' needs IO::Compress::Adapter::Lzma\n" if $method == 95 ;
if ! defined $IO::Compress::Lzma::VERSION;
} installModule("Zstd")
if $method == 93;
$compression_method = $method; $compression_method = $method;
} }
sub installModule
{
my $name = shift ;
eval " use IO::Compress::$name; use IO::Compress::Adapter::$name ; " ;
die "Method '$name' needs IO::Compress::$name\n"
if $@;
}
sub Usage sub Usage
{ {
print <<EOM; print <<EOM;
Usage: Usage:
producer | streamzip [OPTIONS] | consumer producer | streamzip [OPTIONS] | consumer
producer | streamzip [OPTIONS] -zipfile=output.zip producer | streamzip [OPTIONS] -zipfile output.zip
Stream data from stdin, compress into a Zip container, and stream to stdout. Stream data from stdin, compress into a Zip container, and stream to stdout.
OPTIONS OPTIONS
-zipfile=F Write zip container to the filename 'F' -zipfile=F Write zip container to the filename 'F'
Outputs to stdout if zipfile not specified. Outputs to stdout if zipfile not specified.
-member-name=M Set member name to 'M' [Default '-'] -member-name=M Set member name to 'M' [Default '-']
-0 ... -9 Set compression level for Deflate
[Default: 6]
-zip64 Create a Zip64-compliant zip file [Default: No] -zip64 Create a Zip64-compliant zip file [Default: No]
Enable Zip64 if input is greater than 4Gig. Enable Zip64 if input is greater than 4Gig.
-stream Force a streamed zip file when zipfile is also enabled. -stream Force a streamed zip file when 'zipfile' option is also enable d.
Only applies when 'zipfile' option is used. [Default: No] Only applies when 'zipfile' option is used. [Default: No]
Stream is always enabled when writing to stdout. Stream is always enabled when writing to stdout.
-method=M Compress using method 'M'. -method=M Compress using method 'M'.
Valid methods are Valid methods are
store Store without compression store Store without compression
deflate Use Deflate compression [Deflault] deflate Use Deflate compression [Deflault]
bzip2 Use Bzip2 compression bzip2 Use Bzip2 compression
lzma Use LZMA compression [needs IO::Compress::Lzma] lzma Use LZMA compression [needs IO::Compress::Lzma]
Lzma needs IO::Compress::Lzma to be installed. xz Use LZMA compression [needs IO::Compress::Xz]
zstd Use LZMA compression [needs IO::Compress::Zstd]
-version Display version number [$VERSION] -version Display version number [$VERSION]
Copyright (c) 2019-2020 Paul Marquess. All rights reserved. Copyright (c) 2019-2021 Paul Marquess. All rights reserved.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. modify it under the same terms as Perl itself.
EOM EOM
exit; exit;
} }
__END__ __END__
=head1 NAME =head1 NAME
skipping to change at line 173 skipping to change at line 207
=item -method=M =item -method=M
Compress using method C<M>. Compress using method C<M>.
Valid method names are Valid method names are
* store Store without compression * store Store without compression
* deflate Use Deflate compression [Deflault] * deflate Use Deflate compression [Deflault]
* bzip2 Use Bzip2 compression * bzip2 Use Bzip2 compression
* lzma Use LZMA compression * lzma Use LZMA compression
* xz Use xz compression
* zstd Use Zstandard compression
Note that Lzma compress needs C<IO::Compress::Lzma> to be installed. Note that Lzma compress needs C<IO::Compress::Lzma> to be installed.
Note that Zstd compress needs C<IO::Compress::Zstd> to be installed.
Default is C<deflate>. Default is C<deflate>.
=item -0, -1, -2, -3, -4, -5, -6, -7, -8, -9
Sets the compression level for C<deflate>. Ignored for all other compression met
hods.
C<-0> means no compression and C<-9> for maximum compression.
Default is 6
=item -version =item -version
Display version number [$VERSION] Display version number
=item -help =item -help
Display help Display help
=back =back
=head2 When to use a Streamed Zip File =head2 Examples
Create a zip file bt reading daa from stdin
$ echo Lorem ipsum dolor sit | perl ./bin/streamzip >abcd.zip
Check the contents of C<abcd,zip> with the standard C<unzip> utility
Archive: abcd.zip
Length Date Time Name
--------- ---------- ----- ----
22 2021-01-08 19:45 -
--------- -------
22 1 file
Notice how the C<Name> is set to C<->.
That is the default for a few zip utilities whwre the member name is not given.
If you want to explicitly name the file, use the C<-member-name> option as follo
ws
$ echo Lorem ipsum dolor sit | perl ./bin/streamzip -member-name latin >abcd
.zip
$ unzip -l abcd.zip
Archive: abcd.zip
Length Date Time Name
--------- ---------- ----- ----
22 2021-01-08 19:47 latin
--------- -------
22 1 file
=head2 When to write a Streamed Zip File
A Streamed Zip File is useful in situations where you cannot seek A Streamed Zip File is useful in situations where you cannot seek
backwards/forwards in the file. backwards/forwards in the file.
A good examples is when you are serving dynamic content from a Web Server A good examples is when you are serving dynamic content from a Web Server
straight into a socket without needing to create a temporary zip file in straight into a socket without needing to create a temporary zip file in
the filesystsm. the filesystsm.
Similarly if your workfow uses a Linux pipelined commands. Similarly if your workfow uses a Linux pipelined commands.
skipping to change at line 211 skipping to change at line 287
General feedback/questions/bug reports should be sent to General feedback/questions/bug reports should be sent to
L<https://github.com/pmqs/IO-Compress/issues> (preferred) or L<https://github.com/pmqs/IO-Compress/issues> (preferred) or
L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>. L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
=head1 AUTHOR =head1 AUTHOR
Paul Marquess F<pmqs@cpan.org>. Paul Marquess F<pmqs@cpan.org>.
=head1 COPYRIGHT =head1 COPYRIGHT
Copyright (c) 2019-2020 Paul Marquess. All rights reserved. Copyright (c) 2019-2021 Paul Marquess. All rights reserved.
This program is free software; you can redistribute it and/or modify it This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. under the same terms as Perl itself.
 End of changes. 20 change blocks. 
19 lines changed or deleted 98 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)