File Coverage

blib/lib/IO/Uncompress/Adapter/Inflate.pm
Criterion Covered Total %
statement 55 60 91.6
branch 12 14 85.7
condition 12 12 100.0
subroutine 15 17 88.2
pod 0 12 0.0
total 94 115 81.7


line stmt bran cond sub pod time code
1             package IO::Uncompress::Adapter::Inflate;
2              
3 96     96   514 use strict;
  96         162  
  96         2983  
4 96     96   362 use warnings;
  96         125  
  96         3711  
5 96     96   394 use bytes;
  96         1653  
  96         561  
6              
7 96     96   3040 use IO::Compress::Base::Common 2.221 qw(:Status);
  96         1618  
  96         13050  
8 96     96   24100 use Compress::Raw::Zlib 2.218 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS);
  96         181185  
  96         60492  
9              
10             our ($VERSION);
11             $VERSION = '2.221';
12              
13              
14              
15             sub mkUncompObject
16             {
17 3538   100 3538 0 7492 my $crc32 = shift || 1;
18 3538   100     7543 my $adler32 = shift || 1;
19 3538   100     7372 my $scan = shift || 0;
20              
21 3538         5115 my $inflate ;
22             my $status ;
23              
24 3538 100       5389 if ($scan)
25             {
26 69         270 ($inflate, $status) = Compress::Raw::Zlib::InflateScan->new(
27             #LimitOutput => 1,
28             CRC32 => $crc32,
29             ADLER32 => $adler32,
30             WindowBits => - MAX_WBITS );
31             }
32             else
33             {
34 3469         10584 ($inflate, $status) = Compress::Raw::Zlib::Inflate->new(
35             AppendOutput => 1,
36             LimitOutput => 1,
37             CRC32 => $crc32,
38             ADLER32 => $adler32,
39             WindowBits => - MAX_WBITS );
40             }
41              
42 3538 50       1400914 return (undef, "Could not create Inflation object: $status", $status)
43             if $status != Z_OK ;
44              
45 3538         26122 return bless {'Inf' => $inflate,
46             'CompSize' => 0,
47             'UnCompSize' => 0,
48             'Error' => '',
49             'ConsumesInput' => 1,
50             } ;
51              
52             }
53              
54             sub uncompr
55             {
56 5762     5762 0 7601 my $self = shift ;
57 5762         6567 my $from = shift ;
58 5762         6453 my $to = shift ;
59 5762         7007 my $eof = shift ;
60              
61 5762         8015 my $inf = $self->{Inf};
62              
63 5762         71175 my $status = $inf->inflate($from, $to, $eof);
64 5762         14021 $self->{ErrorNo} = $status;
65 5762 100 100     13331 if ($status != Z_OK && $status != Z_STREAM_END && $status != Z_BUF_ERROR)
      100        
66             {
67 1174         11500 $self->{Error} = "Inflation Error: $status";
68 1174         2802 return STATUS_ERROR;
69             }
70              
71 4588 100       32722 return STATUS_OK if $status == Z_BUF_ERROR ; # ???
72 4321 100       13551 return STATUS_OK if $status == Z_OK ;
73 3726 50       11273 return STATUS_ENDSTREAM if $status == Z_STREAM_END ;
74 0         0 return STATUS_ERROR ;
75             }
76              
77             sub reset
78             {
79 2630     2630 0 3213 my $self = shift ;
80 2630         11571 $self->{Inf}->inflateReset();
81              
82 2630         4978 return STATUS_OK ;
83             }
84              
85             #sub count
86             #{
87             # my $self = shift ;
88             # $self->{Inf}->inflateCount();
89             #}
90              
91             sub crc32
92             {
93 1618     1618 0 1950 my $self = shift ;
94 1618         6050 $self->{Inf}->crc32();
95             }
96              
97             sub compressedBytes
98             {
99 0     0 0 0 my $self = shift ;
100 0         0 $self->{Inf}->compressedBytes();
101             }
102              
103             sub uncompressedBytes
104             {
105 0     0 0 0 my $self = shift ;
106 0         0 $self->{Inf}->uncompressedBytes();
107             }
108              
109             sub adler32
110             {
111 490     490 0 537 my $self = shift ;
112 490         1710 $self->{Inf}->adler32();
113             }
114              
115             sub sync
116             {
117 1184     1184 0 1094 my $self = shift ;
118 1184 100       2300 ( $self->{Inf}->inflateSync(@_) == Z_OK)
119             ? STATUS_OK
120             : STATUS_ERROR ;
121             }
122              
123              
124             sub getLastBlockOffset
125             {
126 60     60 0 70 my $self = shift ;
127 60         205 $self->{Inf}->getLastBlockOffset();
128             }
129              
130             sub getEndOffset
131             {
132 60     60 0 70 my $self = shift ;
133 60         154 $self->{Inf}->getEndOffset();
134             }
135              
136             sub resetLastBlockByte
137             {
138 60     60 0 80 my $self = shift ;
139 60         157 $self->{Inf}->resetLastBlockByte(@_);
140             }
141              
142             sub createDeflateStream
143             {
144 60     60 0 79 my $self = shift ;
145 60         178 my $deflate = $self->{Inf}->createDeflateStream(@_);
146 60         27375 return bless {'Def' => $deflate,
147             'CompSize' => 0,
148             'UnCompSize' => 0,
149             'Error' => '',
150             }, 'IO::Compress::Adapter::Deflate';
151             }
152              
153             1;
154              
155              
156             __END__