package IO::Compress::Lzop ; use strict ; use warnings; require Exporter ; use bytes; use IO::Compress::Base 2.020 ; use IO::Compress::Base::Common 2.020 qw(createSelfTiedObject); use IO::Compress::Adapter::LZO 2.020 ; use Compress::LZO qw(crc32 adler32 LZO_VERSION); use IO::Compress::Lzop::Constants 2.020 ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $LzopError); $VERSION = '2.020'; $LzopError = ''; @ISA = qw(Exporter IO::Compress::Base); @EXPORT_OK = qw( $LzopError lzop ) ; %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, \$LzopError); return $obj->_create(undef, @_); } sub lzop { my $obj = createSelfTiedObject(undef, \$LzopError); return $obj->_def(@_); } #sub ckSum #{ # my $self = shift ; # # return adler32($_[0]) if *$self->{LZOP}{Adler32} ; # return crc32($_[0]) if *$self->{LZOP}{CRRC32} ; # return ''; #} sub mkHeader { my $self = shift ; my $param = shift ; my $filename = ''; my $time = $param->value('Time') ; my $flags = F_OS_UNIX ; if (! $param->value('Minimal')) { $flags |= F_ADLER32_D | F_ADLER32_C ; $filename = $param->value('Name') || ''; } my $mode = 0 ; if ($param->value('Mode')) { $mode = $param->value('Mode'); } my $xtr = ''; if ($param->parsed('Extra')) { $flags |= F_H_EXTRA_FIELD ; my $extra = $param->value('Extra') ; $xtr .= pack 'N', length($extra) ; # Extra Length $xtr .= $extra ; # Extra Data $xtr .= pack 'N', adler32($xtr) ; # Extra CRC } my $hdr = '' ; $hdr .= pack 'n', 0x1010 ; # lzop Version $hdr .= pack 'n', 0x1080 ; # LZO library version $hdr .= pack 'n', 0x1010 ; # lzop extract version $hdr .= pack 'C', 1 ; # Method $hdr .= pack 'C', 5 ; # Level $hdr .= pack 'N', $flags ; # Flags $hdr .= pack 'N', $mode ; # Mode $hdr .= pack 'N', $time ; # Time $hdr .= pack 'N', 0 ; # GMDiff # Filename $hdr .= pack 'C', length $filename ; # filename length $hdr .= $filename ; # Header CRC $hdr .= pack 'N', adler32($hdr) ; # Header CRC # Extra $hdr .= $xtr; return SIGNATURE . $hdr; } sub ckParams { my $self = shift ; my $got = shift; if (! $got->parsed('Time') ) { # Modification time defaults to now. $got->value('Time' => time) ; } #*$self->{LZOP}{Adler32} = ($got->value('??') ? 0 : 1) ; return 1 ; } sub mkComp { my $self = shift ; my $got = shift ; my ($obj, $errstr, $errno) = IO::Compress::Adapter::LZO::mkCompObject( $got->value('BlockSize'), $got->value('Optimize'), $got->value('Minimal'), ); return $self->saveErrorString(undef, $errstr, $errno) if ! defined $obj; return $obj; } sub mkTrailer { my $self = shift ; return pack "N", 0 ; } sub mkFinalTrailer { return ''; } #sub newHeader #{ # my $self = shift ; # return ''; #} sub getExtraParams { my $self = shift ; use IO::Compress::Base::Common 2.020 qw(:Parse); return ( 'Name' => [0, 1, Parse_any, undef], 'Time' => [0, 1, Parse_any, undef], 'Mode' => [0, 1, Parse_any, 0], 'Extra' => [0, 1, Parse_any, undef], 'Minimal' => [0, 1, Parse_boolean, 0], 'BlockSize' => [0, 1, Parse_unsigned, BLOCK_SIZE], 'Optimize' => [0, 1, Parse_boolean, 1], # TODO # none # crc32 # adler32 ); } sub getInverseClass { return ('IO::Uncompress::UnLzop'); } sub getFileInfo { my $self = shift ; my $params = shift; my $filename = shift ; my ($defaultMode, $defaultTime) = (stat($filename))[2, 9] ; $params->value('Name' => $filename) if ! $params->parsed('Name') ; $params->value('Time' => $defaultTime) if ! $params->parsed('Time') ; $params->value('Mode' => $defaultMode) if ! $params->parsed('Mode') ; } 1; __END__ =head1 NAME IO::Compress::Lzop - Write lzop files/buffers =head1 SYNOPSIS use IO::Compress::Lzop qw(lzop $LzopError) ; my $status = lzop $input => $output [,OPTS] or die "lzop failed: $LzopError\n"; my $z = new IO::Compress::Lzop $output [,OPTS] or die "lzop failed: $LzopError\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() ; $LzopError ; # 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 lzop compressed data to files or buffer. For reading lzop 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 section. use IO::Compress::Lzop qw(lzop $LzopError) ; lzop $input => $output [,OPTS] or die "lzop failed: $LzopError\n"; The functional interface needs Perl5.005 or better. =head2 lzop $input => $output [, OPTS] C expects at least two parameters, C<$input> and C<$output>. =head3 The C<$input> parameter The parameter, C<$input>, 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> 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> 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> is a scalar reference, the input data will be read from C<$$input>. =item An array reference If C<$input> 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> 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. If the fileglob does not match any files ... See L for more details. =back If the C<$input> parameter is any other type, C will be returned. In addition, if C<$input> is a simple filename, the default values for the C and C