Commit | Line | Data |
1a6a8453 |
1 | package CompressPlugin::Deflate ; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Compress::Zlib::Common qw(:Status); |
7 | |
8 | use Compress::Zlib qw(Z_OK Z_FINISH MAX_WBITS) ; |
9 | our ($VERSION); |
10 | |
11 | $VERSION = '2.000_05'; |
12 | |
13 | sub mkCompObject |
14 | { |
15 | my $crc32 = shift ; |
16 | my $adler32 = shift ; |
17 | my $level = shift ; |
18 | my $strategy = shift ; |
19 | |
20 | my ($def, $status) = new Compress::Zlib::Deflate |
21 | -AppendOutput => 1, |
22 | -CRC32 => $crc32, |
23 | -ADLER32 => $adler32, |
24 | -Level => $level, |
25 | -Strategy => $strategy, |
26 | -WindowBits => - MAX_WBITS; |
27 | |
28 | return (undef, "Cannot create Deflate object: $status", $status) |
29 | if $status != Z_OK; |
30 | |
31 | return bless {'Def' => $def, |
32 | 'CompSize' => 0, |
33 | 'UnCompSize' => 0, |
34 | 'Error' => '', |
35 | } ; |
36 | } |
37 | |
38 | sub compr |
39 | { |
40 | my $self = shift ; |
41 | |
42 | my $def = $self->{Def}; |
43 | |
44 | my $status = $def->deflate($_[0], $_[1]) ; |
45 | $self->{ErrorNo} = $status; |
46 | |
47 | if ($status != Z_OK) |
48 | { |
49 | $self->{Error} = "Deflate Error: $status"; |
50 | return STATUS_ERROR; |
51 | } |
52 | |
53 | return STATUS_OK; |
54 | } |
55 | |
56 | sub flush |
57 | { |
58 | my $self = shift ; |
59 | |
60 | my $def = $self->{Def}; |
61 | |
62 | my $opt = $_[1] || Z_FINISH; |
63 | my $status = $def->flush($_[0], $opt); |
64 | $self->{ErrorNo} = $status; |
65 | |
66 | if ($status != Z_OK) |
67 | { |
68 | $self->{Error} = "Deflate Error: $status"; |
69 | return STATUS_ERROR; |
70 | } |
71 | |
72 | return STATUS_OK; |
73 | |
74 | } |
75 | |
76 | sub close |
77 | { |
78 | my $self = shift ; |
79 | |
80 | my $def = $self->{Def}; |
81 | |
82 | $def->flush($_[0], Z_FINISH); |
83 | } |
84 | |
85 | sub reset |
86 | { |
87 | my $self = shift ; |
88 | |
89 | my $def = $self->{Def}; |
90 | |
91 | my $status = $def->deflateReset() ; |
92 | $self->{ErrorNo} = $status; |
93 | if ($status != Z_OK) |
94 | { |
95 | $self->{Error} = "Deflate Error: $status"; |
96 | return STATUS_ERROR; |
97 | } |
98 | |
99 | return STATUS_OK; |
100 | } |
101 | |
102 | sub deflateParams |
103 | { |
104 | my $self = shift ; |
105 | |
106 | my $def = $self->{Def}; |
107 | |
108 | my $status = $def->deflateParams(@_); |
109 | $self->{ErrorNo} = $status; |
110 | if ($status != Z_OK) |
111 | { |
112 | $self->{Error} = "deflateParams Error: $status"; |
113 | return STATUS_ERROR; |
114 | } |
115 | |
116 | return STATUS_OK; |
117 | } |
118 | |
119 | |
120 | |
121 | sub total_out |
122 | { |
123 | my $self = shift ; |
124 | $self->{Def}->total_out(); |
125 | } |
126 | |
127 | sub total_in |
128 | { |
129 | my $self = shift ; |
130 | $self->{Def}->total_in(); |
131 | } |
132 | |
133 | sub compressedBytes |
134 | { |
135 | my $self = shift ; |
136 | $self->{Def}->compressedBytes(); |
137 | } |
138 | |
139 | sub uncompressedBytes |
140 | { |
141 | my $self = shift ; |
142 | $self->{Def}->uncompressedBytes(); |
143 | } |
144 | |
145 | |
146 | |
147 | |
148 | sub crc32 |
149 | { |
150 | my $self = shift ; |
151 | $self->{Def}->crc32(); |
152 | } |
153 | |
154 | sub adler32 |
155 | { |
156 | my $self = shift ; |
157 | $self->{Def}->adler32(); |
158 | } |
159 | |
160 | |
161 | 1; |
162 | |
163 | __END__ |
164 | |