| 1 | package IO::Compress::Lzip ; | ||
| 2 | |||
| 3 | 11 | ▶ | use strict ; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 11 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 11 | ▶ | use bytes; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | require Exporter ; | ||
| 7 | |||
| 8 | 11 | ▶ | use IO::Compress::Base 2.225 ; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 11 | ▶ | use IO::Compress::Base::Common 2.225 qw(createSelfTiedObject); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 0 | ▶ | use IO::Compress::Adapter::Lzip 2.225 ; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | |||
| 13 | our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $LzipError); | ||
| 14 | |||
| 15 | $VERSION = '2.225'; | ||
| 16 | $LzipError = ''; | ||
| 17 | |||
| 18 | @ISA = qw(IO::Compress::Base Exporter); | ||
| 19 | @EXPORT_OK = qw( $LzipError lzip ) ; | ||
| 20 | %EXPORT_TAGS = %IO::Compress::Base::EXPORT_TAGS ; | ||
| 21 | $EXPORT_TAGS{all} = [ defined $EXPORT_TAGS{all} ? @{ $EXPORT_TAGS{all} } : (), @EXPORT_OK ] ; | ||
| 22 | Exporter::export_ok_tags('all'); | ||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | sub new | ||
| 27 | { | ||
| 28 | my $class = shift ; | ||
| 29 | |||
| 30 | my $obj = createSelfTiedObject($class, \$LzipError); | ||
| 31 | return $obj->_create(undef, @_); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub lzip | ||
| 35 | { | ||
| 36 | my $obj = createSelfTiedObject(undef, \$LzipError); | ||
| 37 | $obj->_def(@_); | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | sub mkHeader | ||
| 42 | { | ||
| 43 | my $self = shift ; | ||
| 44 | my $opts = shift ; | ||
| 45 | |||
| 46 | my $header = "LZIP\x01" ; | ||
| 47 | |||
| 48 | # Code below to calculate dictionary size derived from libarchive archive_write_add_filter_xz.c | ||
| 49 | |||
| 50 | # Hard-wire size for now | ||
| 51 | # my $dict_size = 1 << 12 ; | ||
| 52 | my $dict_size = $opts->getValue('dictsize'); | ||
| 53 | |||
| 54 | my ($ds, $log2dic, $wedges); | ||
| 55 | |||
| 56 | $self->saveErrorString(undef, "Unacceptable dictionary size for lzip: $dict_size") | ||
| 57 | if $dict_size < (1 << 12) || $dict_size > (1 << 27) ; | ||
| 58 | |||
| 59 | for ($log2dic = 27; $log2dic >= 12; $log2dic--) | ||
| 60 | { | ||
| 61 | last | ||
| 62 | if $dict_size & (1 << $log2dic) ; | ||
| 63 | } | ||
| 64 | |||
| 65 | if ($dict_size > (1 << $log2dic)) | ||
| 66 | { | ||
| 67 | ++ $log2dic ; | ||
| 68 | $wedges = ((1 << $log2dic) - $dict_size) / (1 << ($log2dic - 4)); | ||
| 69 | } | ||
| 70 | else | ||
| 71 | { | ||
| 72 | $wedges = 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | $ds = (($wedges << 5) & 0xe0) | ($log2dic & 0x1f); | ||
| 76 | |||
| 77 | $header .= pack ("C", $ds) ; | ||
| 78 | |||
| 79 | return $header; | ||
| 80 | } | ||
| 81 | |||
| 82 | our %PARAMS = ('dictsize' => [IO::Compress::Base::Common::Parse_unsigned, 1 << 23 ], # 8 Meg | ||
| 83 | ); | ||
| 84 | sub getExtraParams | ||
| 85 | { | ||
| 86 | return %PARAMS ; | ||
| 87 | } | ||
| 88 | |||
| 89 | sub ckParams | ||
| 90 | { | ||
| 91 | my $self = shift ; | ||
| 92 | my $got = shift; | ||
| 93 | |||
| 94 | return 1 ; | ||
| 95 | } | ||
| 96 | |||
| 97 | sub mkComp | ||
| 98 | { | ||
| 99 | my $self = shift ; | ||
| 100 | my $got = shift ; | ||
| 101 | |||
| 102 | my $DictSize = $got->getValue('dictsize'); | ||
| 103 | |||
| 104 | my ($obj, $errstr, $errno) = | ||
| 105 | IO::Compress::Adapter::Lzip::mkCompObject($DictSize); | ||
| 106 | |||
| 107 | return $self->saveErrorString(undef, $errstr, $errno) | ||
| 108 | if ! defined $obj; | ||
| 109 | |||
| 110 | return $obj; | ||
| 111 | } | ||
| 112 | |||
| 113 | sub mkTrailer | ||
| 114 | { | ||
| 115 | my $self = shift ; | ||
| 116 | |||
| 117 | *$self->{CompSize}->add( 6 + 20); # Compressed size + header + trailer | ||
| 118 | |||
| 119 | return pack("V", *$self->{Compress}->crc32() ) . | ||
| 120 | *$self->{UnCompSize}->getPacked_V64() . # Uncompressed size | ||
| 121 | |||
| 122 | *$self->{CompSize}->getPacked_V64() ; # Compressed size | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | sub mkFinalTrailer | ||
| 127 | { | ||
| 128 | return ''; | ||
| 129 | } | ||
| 130 | |||
| 131 | #sub newHeader | ||
| 132 | #{ | ||
| 133 | # my $self = shift ; | ||
| 134 | # return ''; | ||
| 135 | #} | ||
| 136 | |||
| 137 | sub getInverseClass | ||
| 138 | { | ||
| 139 | return ('IO::Uncompress::UnLzip'); | ||
| 140 | } | ||
| 141 | |||
| 142 | sub getFileInfo | ||
| 143 | { | ||
| 144 | my $self = shift ; | ||
| 145 | my $params = shift; | ||
| 146 | my $file = shift ; | ||
| 147 | |||
| 148 | } | ||
| 149 | |||
| 150 | 1; | ||
| 151 | |||
| 152 | __END__ | ||