Uncompress/Adapter/UnLzip.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Compress/Adapter/Xz.pm ↑ Summary Uncompress/Adapter/UnLzma.pm »
1 package IO::Uncompress::Adapter::UnLzip;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use IO::Compress::Base::Common 2.217 qw(:Status);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use Compress::Raw::Lzma 2.217 ;
Subroutine BEGIN: called CC=1 SCAR=2.6
10  
11 our ($VERSION, @ISA);
12 $VERSION = '2.217';
13  
14 #@ISA = qw( Compress::Raw::UnLzma );
15  
16  
17 sub mkUncompObject
18 {
19 my $dictSize = shift;
20  
21 # my $properties ;
22 # my $filter = Lzma::Filter::Lzma1(DictSize => $dictSize,
23 # #'PreserDict' => [1, 1, Parse_unsigned(), undef],
24 # # 'Lc' => [1, 1, Parse_unsigned(), LZMA_LC_DEFAULT()],
25 # # 'Lp' => [1, 1, Parse_unsigned(), LZMA_LP_DEFAULT()],
26 # # 'Pb' => [1, 1, Parse_unsigned(), LZMA_PB_DEFAULT()],
27 # # 'Mode' => [1, 1, Parse_unsigned(), LZMA_MODE_NORMAL()],
28 # # 'Nice' => [1, 1, Parse_unsigned(), 64],
29 # # 'Mf' => [1, 1, Parse_unsigned(), LZMA_MF_BT4()],
30 # # 'Depth' => [1, 1, Parse_unsigned(), 0],
31 # );
32  
33 # From lzip_init (in archive_read_support_filter_xz.c)
34 my $properties = pack("C V", 0x5D, 1 << ($dictSize & 0x1F));
35  
36 my ($inflate, $status) = Compress::Raw::Lzma::RawDecoder->new(AppendOutput => 1,
37 Properties => $properties,
38 # Filter => $filter,
39 ConsumeInput => 1,
40 LimitOutput => 1);
41  
42 return (undef, "Could not create RawDecoder object: $status", $status)
43 if $status != LZMA_OK ;
44  
45 return bless {'Inf' => $inflate,
46 'CompSize' => 0,
47 'UnCompSize' => 0,
48 'Error' => '',
49 'ErrorNo' => 0,
50 'ConsumesInput' => 1,
51 'CRC32' => 0,
52 'Properties' => $properties,
53 } ;
54  
55 }
56  
57 sub uncompr
58 {
59 my $self = shift ;
60 my $from = shift ;
61 my $to = shift ;
62 my $eof = shift ;
63  
64 my $len = length($$to) ;
65 my $inf = $self->{Inf};
66 my $status = $inf->code($from, $to);
67 $self->{ErrorNo} = $status;
68  
69 if ($status != LZMA_OK && $status != LZMA_STREAM_END )
70 {
71 $self->{Error} = "Uncompression Error: $status";
72 return STATUS_ERROR;
73 }
74  
75 $self->{CRC32} = Compress::Raw::Zlib::crc32(substr($$to, $len), $self->{CRC32})
76 if length($$to) > $len ;
77  
78 return STATUS_ENDSTREAM if $status == LZMA_STREAM_END ||
79 ($eof && length $$from == 0);
80  
81  
82 return STATUS_OK if $status == LZMA_OK ;
83 return STATUS_ERROR ;
84 }
85  
86  
87 sub reset
88 {
89 my $self = shift ;
90  
91 my ($inf, $status) = Compress::Raw::Lzma::RawDecoder->new(AppendOutput => 1,
92 Properties => $self->{Properties},
93 # Filter => $filter,
94 ConsumeInput => 1,
95 LimitOutput => 1);
96  
97 # my ($inf, $status) = Compress::Raw::Lzma::RawDecoder->new(AppendOutput => 1,
98 # ConsumeInput => 1,
99 # LimitOutput => 1);
100 $self->{ErrorNo} = ($status == LZMA_OK) ? 0 : $status ;
101  
102 if ($status != LZMA_OK)
103 {
104 $self->{Error} = "Cannot create UnLzma object: $status";
105 return STATUS_ERROR;
106 }
107  
108 $self->{Inf} = $inf;
109 $self->{CRC32} = 0 ;
110  
111 return STATUS_OK ;
112 }
113  
114 #sub count
115 #{
116 # my $self = shift ;
117 # $self->{Inf}->inflateCount();
118 #}
119  
120 sub compressedBytes
121 {
122 my $self = shift ;
123 $self->{Inf}->compressedBytes();
124 }
125  
126 sub uncompressedBytes
127 {
128 my $self = shift ;
129 $self->{Inf}->uncompressedBytes();
130 }
131  
132 sub crc32
133 {
134 my $self = shift ;
135 $self->{CRC32};
136 }
137  
138 sub adler32
139 {
140 my $self = shift ;
141 #$self->{Inf}->adler32();
142 }
143  
144 sub sync
145 {
146 my $self = shift ;
147 #( $self->{Inf}->inflateSync(@_) == LZMA_OK)
148 # ? STATUS_OK
149 # : STATUS_ERROR ;
150 }
151  
152  
153 1;
154  
155 __END__
« Compress/Adapter/Xz.pm ↑ Summary Uncompress/Adapter/UnLzma.pm »