File Coverage

blib/lib/IO/Compress/Adapter/Deflate.pm
Criterion Covered Total %
statement 55 73 75.3
branch 7 14 50.0
condition 2 3 66.6
subroutine 12 16 75.0
pod 0 11 0.0
total 76 117 64.9


line stmt bran cond sub pod time code
1             package IO::Compress::Adapter::Deflate ;
2              
3 103     103   255258 use strict;
  103         282  
  103         7252  
4 103     103   523 use warnings;
  103         222  
  103         6326  
5 103     103   611 use bytes;
  103         227  
  103         728  
6              
7 103     103   4464 use IO::Compress::Base::Common 2.219 qw(:Status);
  103         2608  
  103         15316  
8 103     103   48344 use Compress::Raw::Zlib 2.218 qw( !crc32 !adler32 ) ;
  103         433957  
  103         150874  
9              
10             require Exporter;
11             our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, @EXPORT, %DEFLATE_CONSTANTS);
12              
13             $VERSION = '2.219';
14             @ISA = qw(Exporter);
15             @EXPORT_OK = @Compress::Raw::Zlib::DEFLATE_CONSTANTS;
16             %EXPORT_TAGS = %Compress::Raw::Zlib::DEFLATE_CONSTANTS;
17             @EXPORT = @EXPORT_OK;
18             %DEFLATE_CONSTANTS = %EXPORT_TAGS ;
19              
20             sub mkCompObject
21             {
22 1072     1072 0 2215 my $crc32 = shift ;
23 1072         2101 my $adler32 = shift ;
24 1072         1991 my $level = shift ;
25 1072         4949 my $strategy = shift ;
26              
27 1072         4926 my ($def, $status) = Compress::Raw::Zlib::Deflate->new(
28             -AppendOutput => 1,
29             -CRC32 => $crc32,
30             -ADLER32 => $adler32,
31             -Level => $level,
32             -Strategy => $strategy,
33             -WindowBits => - MAX_WBITS);
34              
35 1072 50       887594 return (undef, "Cannot create Deflate object: $status", $status)
36             if $status != Z_OK;
37              
38 1072         16959 return bless {'Def' => $def,
39             'Error' => '',
40             } ;
41             }
42              
43             sub mkCompObject1
44             {
45 299     299 0 3085 my $crc32 = shift ;
46 299         547 my $adler32 = shift ;
47 299         13746 my $level = shift ;
48 299         514 my $strategy = shift ;
49              
50 299         1403 my ($def, $status) = Compress::Raw::Zlib::Deflate->new(
51             -AppendOutput => 1,
52             -CRC32 => $crc32,
53             -ADLER32 => $adler32,
54             -Level => $level,
55             -Strategy => $strategy,
56             -WindowBits => MAX_WBITS);
57              
58 299 50       279601 return (undef, "Cannot create Deflate object: $status", $status)
59             if $status != Z_OK;
60              
61 299         3753 return bless {'Def' => $def,
62             'Error' => '',
63             } ;
64             }
65              
66             sub compr
67             {
68 1350     1350 0 2558 my $self = shift ;
69              
70 1350         3565 my $def = $self->{Def};
71              
72 1350         70614 my $status = $def->deflate($_[0], $_[1]) ;
73 1350         4721 $self->{ErrorNo} = $status;
74              
75 1350 50       5194 if ($status != Z_OK)
76             {
77 0         0 $self->{Error} = "Deflate Error: $status";
78 0         0 return STATUS_ERROR;
79             }
80              
81 1350         8000 return STATUS_OK;
82             }
83              
84             sub flush
85             {
86 31     31 0 65 my $self = shift ;
87              
88 31         74 my $def = $self->{Def};
89              
90 31   66     173 my $opt = $_[1] || Z_FINISH;
91 31         936 my $status = $def->flush($_[0], $opt);
92 31         114 $self->{ErrorNo} = $status;
93              
94 31 100       135 if ($status != Z_OK)
95             {
96 1         8 $self->{Error} = "Deflate Error: $status";
97 1         4 return STATUS_ERROR;
98             }
99              
100 30         207 return STATUS_OK;
101             }
102              
103             sub close
104             {
105 1426     1426 0 4805 my $self = shift ;
106              
107 1426         3300 my $def = $self->{Def};
108              
109 1426 50       8647 $def->flush($_[0], Z_FINISH)
110             if defined $def ;
111             }
112              
113             sub reset
114             {
115 0     0 0 0 my $self = shift ;
116              
117 0         0 my $def = $self->{Def};
118              
119 0         0 my $status = $def->deflateReset() ;
120 0         0 $self->{ErrorNo} = $status;
121 0 0       0 if ($status != Z_OK)
122             {
123 0         0 $self->{Error} = "Deflate Error: $status";
124 0         0 return STATUS_ERROR;
125             }
126              
127 0         0 return STATUS_OK;
128             }
129              
130             sub deflateParams
131             {
132 4     4 0 8 my $self = shift ;
133              
134 4         12 my $def = $self->{Def};
135              
136 4         20 my $status = $def->deflateParams(@_);
137 4         1635 $self->{ErrorNo} = $status;
138 4 50       21 if ($status != Z_OK)
139             {
140 0         0 $self->{Error} = "deflateParams Error: $status";
141 0         0 return STATUS_ERROR;
142             }
143              
144 4         32 return STATUS_OK;
145             }
146              
147              
148              
149             #sub total_out
150             #{
151             # my $self = shift ;
152             # $self->{Def}->total_out();
153             #}
154             #
155             #sub total_in
156             #{
157             # my $self = shift ;
158             # $self->{Def}->total_in();
159             #}
160              
161             sub compressedBytes
162             {
163 0     0 0 0 my $self = shift ;
164              
165 0         0 $self->{Def}->compressedBytes();
166             }
167              
168             sub uncompressedBytes
169             {
170 0     0 0 0 my $self = shift ;
171 0         0 $self->{Def}->uncompressedBytes();
172             }
173              
174              
175              
176              
177             sub crc32
178             {
179 1135     1135 0 2180 my $self = shift ;
180 1135         7893 $self->{Def}->crc32();
181             }
182              
183             sub adler32
184             {
185 0     0 0   my $self = shift ;
186 0           $self->{Def}->adler32();
187             }
188              
189              
190             1;
191              
192             __END__