package IO::Compress::Lzip ;
use strict ;
use warnings;
use bytes;
require Exporter ;
use IO::Compress::Base 2.101 ;
use IO::Compress::Base::Common 2.101 qw(createSelfTiedObject);
use IO::Compress::Adapter::Lzip 2.101 ;
our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $LzipError);
$VERSION = '2.101';
$LzipError = '';
@ISA = qw(IO::Compress::Base Exporter);
@EXPORT_OK = qw( $LzipError lzip ) ;
%EXPORT_TAGS = %IO::Compress::Base::EXPORT_TAGS ;
push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
Exporter::export_ok_tags('all');
sub new
{
my $class = shift ;
my $obj = createSelfTiedObject($class, \$LzipError);
return $obj->_create(undef, @_);
}
sub lzip
{
my $obj = createSelfTiedObject(undef, \$LzipError);
$obj->_def(@_);
}
sub mkHeader
{
my $self = shift ;
my $opts = shift ;
my $header = "LZIP\x01" ;
# Code below to calculate dictionary size derived from libarchive archive_write_add_filter_xz.c
# Hard-wire size for now
# my $dict_size = 1 << 12 ;
my $dict_size = $opts->getValue('dictsize');
my ($ds, $log2dic, $wedges);
$self->saveErrorString(undef, "Unacceptable dictionary size for lzip: $dict_size")
if $dict_size < (1 << 12) || $dict_size > (1 << 27) ;
for ($log2dic = 27; $log2dic >= 12; $log2dic--)
{
last
if $dict_size & (1 << $log2dic) ;
}
if ($dict_size > (1 << $log2dic))
{
++ $log2dic ;
$wedges = ((1 << $log2dic) - $dict_size) / (1 << ($log2dic - 4));
}
else
{
$wedges = 0;
}
$ds = (($wedges << 5) & 0xe0) | ($log2dic & 0x1f);
$header .= pack ("C", $ds) ;
return $header;
}
our %PARAMS = ('dictsize' => [IO::Compress::Base::Common::Parse_unsigned, 1 << 23 ], # 8 Meg
);
sub getExtraParams
{
return %PARAMS ;
}
sub ckParams
{
my $self = shift ;
my $got = shift;
return 1 ;
}
sub mkComp
{
my $self = shift ;
my $got = shift ;
my $DictSize = $got->getValue('dictsize');
my ($obj, $errstr, $errno) =
IO::Compress::Adapter::Lzip::mkCompObject($DictSize);
return $self->saveErrorString(undef, $errstr, $errno)
if ! defined $obj;
return $obj;
}
sub mkTrailer
{
my $self = shift ;
*$self->{CompSize}->add( 6 + 20); # Compressed size + header + trailer
return pack("V", *$self->{Compress}->crc32() ) .
*$self->{UnCompSize}->getPacked_V64() . # Uncompressed size
*$self->{CompSize}->getPacked_V64() ; # Compressed size
}
sub mkFinalTrailer
{
return '';
}
#sub newHeader
#{
# my $self = shift ;
# return '';
#}
sub getInverseClass
{
return ('IO::Uncompress::UnLzip');
}
sub getFileInfo
{
my $self = shift ;
my $params = shift;
my $file = shift ;
}
1;
__END__
=head1 NAME
IO::Compress::Lzip - Write lzip files/buffers
=head1 SYNOPSIS
use IO::Compress::Lzip qw(lzip $LzipError) ;
my $status = lzip $input => $output [,OPTS]
or die "lzip failed: $LzipError\n";
my $z = IO::Compress::Lzip->new( $output [,OPTS] )
or die "lzip failed: $LzipError\n";
$z->print($string);
$z->printf($format, $string);
$z->write($string);
$z->syswrite($string [, $length, $offset]);
$z->flush();
$z->tell();
$z->eof();
$z->seek($position, $whence);
$z->binmode();
$z->fileno();
$z->opened();
$z->autoflush();
$z->input_line_number();
$z->newStream( [OPTS] );
$z->close() ;
$LzipError ;
# IO::File mode
print $z $string;
printf $z $format, $string;
tell $z
eof $z
seek $z, $position, $whence
binmode $z
fileno $z
close $z ;
=head1 DESCRIPTION
This module provides a Perl interface that allows writing lzip
compressed data to files or buffer.
For reading lzip files/buffers, see the companion module
L.
=head1 Functional Interface
A top-level function, C, is provided to carry out
"one-shot" compression between buffers and/or files. For finer
control over the compression process, see the L"OO Interface">
section.
use IO::Compress::Lzip qw(lzip $LzipError) ;
lzip $input_filename_or_reference => $output_filename_or_reference [,OPTS]
or die "lzip failed: $LzipError\n";
The functional interface needs Perl5.005 or better.
=head2 lzip $input_filename_or_reference => $output_filename_or_reference [, OPTS]
C expects at least two parameters,
C<$input_filename_or_reference> and C<$output_filename_or_reference>
and zero or more optional parameters (see L)
=head3 The C<$input_filename_or_reference> parameter
The parameter, C<$input_filename_or_reference>, is used to define the
source of the uncompressed data.
It can take one of the following forms:
=over 5
=item A filename
If the C<$input_filename_or_reference> parameter is a simple scalar, it is
assumed to be a filename. This file will be opened for reading and the
input data will be read from it.
=item A filehandle
If the C<$input_filename_or_reference> parameter is a filehandle, the input
data will be read from it. The string '-' can be used as an alias for
standard input.
=item A scalar reference
If C<$input_filename_or_reference> is a scalar reference, the input data
will be read from C<$$input_filename_or_reference>.
=item An array reference
If C<$input_filename_or_reference> is an array reference, each element in
the array must be a filename.
The input data will be read from each file in turn.
The complete array will be walked to ensure that it only
contains valid filenames before any data is compressed.
=item An Input FileGlob string
If C<$input_filename_or_reference> is a string that is delimited by the
characters "<" and ">" C will assume that it is an
I. The input is the list of files that match the
fileglob.
See L for more details.
=back
If the C<$input_filename_or_reference> parameter is any other type,
C will be returned.
=head3 The C<$output_filename_or_reference> parameter
The parameter C<$output_filename_or_reference> is used to control the
destination of the compressed data. This parameter can take one of
these forms.
=over 5
=item A filename
If the C<$output_filename_or_reference> parameter is a simple scalar, it is
assumed to be a filename. This file will be opened for writing and the
compressed data will be written to it.
=item A filehandle
If the C<$output_filename_or_reference> parameter is a filehandle, the
compressed data will be written to it. The string '-' can be used as
an alias for standard output.
=item A scalar reference
If C<$output_filename_or_reference> is a scalar reference, the
compressed data will be stored in C<$$output_filename_or_reference>.
=item An Array Reference
If C<$output_filename_or_reference> is an array reference,
the compressed data will be pushed onto the array.
=item An Output FileGlob
If C<$output_filename_or_reference> is a string that is delimited by the
characters "<" and ">" C will assume that it is an
I