| 1 | package IO::Compress::Adapter::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 | |||
| 7 | 11 | ▶ | use IO::Compress::Base::Common 2.225 qw(:Status); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 0 | ▶ | use Compress::Raw::Lzma 2.225 qw(LZMA_OK LZMA_STREAM_END) ; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use Compress::Raw::Zlib 2.225 qw() ; | ||
| 11 | |||
| 12 | our ($VERSION); | ||
| 13 | $VERSION = '2.225'; | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | sub mkCompObject | ||
| 18 | { | ||
| 19 | my $dictSize = shift ; | ||
| 20 | |||
| 21 | my $filter = Lzma::Filter::Lzma1(DictSize => $dictSize); | ||
| 22 | |||
| 23 | my ($def, $status) = | ||
| 24 | Compress::Raw::Lzma::RawEncoder->new(AppendOutput => 1, | ||
| 25 | ForZip => 0, | ||
| 26 | Filter => $filter, | ||
| 27 | #Filter => Lzma::Filter::Lzma1m | ||
| 28 | ); | ||
| 29 | |||
| 30 | return (undef, "Could not create RawEncoder object: $status", $status) | ||
| 31 | if $status != LZMA_OK ; | ||
| 32 | |||
| 33 | return bless {'Def' => $def, | ||
| 34 | 'Error' => '', | ||
| 35 | 'ErrorNo' => 0, | ||
| 36 | 'CRC32' => 0, | ||
| 37 | } ; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub compr | ||
| 41 | { | ||
| 42 | my $self = shift ; | ||
| 43 | |||
| 44 | my $def = $self->{Def}; | ||
| 45 | |||
| 46 | $self->{CRC32} = Compress::Raw::Zlib::crc32($_[0], $self->{CRC32}) ; | ||
| 47 | |||
| 48 | my $status = $def->code($_[0], $_[1]) ; | ||
| 49 | $self->{ErrorNo} = $status; | ||
| 50 | |||
| 51 | if ($status != LZMA_OK) | ||
| 52 | { | ||
| 53 | $self->{Error} = "Deflate Error: $status"; | ||
| 54 | return STATUS_ERROR; | ||
| 55 | } | ||
| 56 | |||
| 57 | #${ $_[1] } .= $out if defined $out; | ||
| 58 | |||
| 59 | return STATUS_OK; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub flush | ||
| 63 | { | ||
| 64 | my $self = shift ; | ||
| 65 | |||
| 66 | my $def = $self->{Def}; | ||
| 67 | |||
| 68 | my $status = $def->flush($_[0]); | ||
| 69 | $self->{ErrorNo} = $status; | ||
| 70 | |||
| 71 | if ($status != LZMA_STREAM_END) | ||
| 72 | { | ||
| 73 | $self->{Error} = "Deflate Error: $status"; | ||
| 74 | return STATUS_ERROR; | ||
| 75 | } | ||
| 76 | |||
| 77 | #${ $_[0] } .= $out if defined $out ; | ||
| 78 | return STATUS_OK; | ||
| 79 | |||
| 80 | } | ||
| 81 | |||
| 82 | sub close | ||
| 83 | { | ||
| 84 | my $self = shift ; | ||
| 85 | |||
| 86 | my $def = $self->{Def}; | ||
| 87 | |||
| 88 | my $status = $def->flush($_[0]); | ||
| 89 | $self->{ErrorNo} = $status; | ||
| 90 | |||
| 91 | if ($status != LZMA_STREAM_END) | ||
| 92 | { | ||
| 93 | $self->{Error} = "Deflate Error: $status"; | ||
| 94 | return STATUS_ERROR; | ||
| 95 | } | ||
| 96 | |||
| 97 | #${ $_[0] } .= $out if defined $out ; | ||
| 98 | return STATUS_OK; | ||
| 99 | |||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | sub reset | ||
| 104 | { | ||
| 105 | my $self = shift ; | ||
| 106 | |||
| 107 | my $outer = $self->{Outer}; | ||
| 108 | |||
| 109 | my ($def, $status) = | ||
| 110 | Compress::Raw::Lzma::RawEncoder->new(AppendOutput => 1); | ||
| 111 | $self->{ErrorNo} = ($status == LZMA_OK) ? 0 : $status ; | ||
| 112 | |||
| 113 | if ($status != LZMA_OK) | ||
| 114 | { | ||
| 115 | $self->{Error} = "Cannot create Deflate object: $status"; | ||
| 116 | return STATUS_ERROR; | ||
| 117 | } | ||
| 118 | |||
| 119 | $self->{Def} = $def; | ||
| 120 | |||
| 121 | return STATUS_OK; | ||
| 122 | } | ||
| 123 | |||
| 124 | sub compressedBytes | ||
| 125 | { | ||
| 126 | my $self = shift ; | ||
| 127 | $self->{Def}->compressedBytes(); | ||
| 128 | } | ||
| 129 | |||
| 130 | sub uncompressedBytes | ||
| 131 | { | ||
| 132 | my $self = shift ; | ||
| 133 | $self->{Def}->uncompressedBytes(); | ||
| 134 | } | ||
| 135 | |||
| 136 | #sub total_out | ||
| 137 | #{ | ||
| 138 | # my $self = shift ; | ||
| 139 | # 0; | ||
| 140 | #} | ||
| 141 | # | ||
| 142 | |||
| 143 | #sub total_in | ||
| 144 | #{ | ||
| 145 | # my $self = shift ; | ||
| 146 | # $self->{Def}->total_in(); | ||
| 147 | #} | ||
| 148 | |||
| 149 | sub crc32 | ||
| 150 | { | ||
| 151 | my $self = shift ; | ||
| 152 | return $self->{CRC32} ; | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | 1; | ||
| 158 | |||
| 159 | __END__ | ||