← Index
NYTProf Performance Profile   « line view »
For /Users/brian/bin/perls/cpan5.26.1
  Run on Sat Dec 30 01:41:10 2017
Reported on Sat Dec 30 01:44:15 2017

Filename/usr/local/perls/perl-5.26.1/lib/5.26.1/Compress/Zlib.pm
StatementsExecuted 21726 statements in 30.0ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
12714122.5ms29.5msCompress::Zlib::::_save_gzerr Compress::Zlib::_save_gzerr
1117.38ms15.1msCompress::Zlib::::BEGIN@10 Compress::Zlib::BEGIN@10
634215.62ms162msCompress::Zlib::gzFile::::gzreadCompress::Zlib::gzFile::gzread
1114.57ms7.93msCompress::Zlib::::BEGIN@11 Compress::Zlib::BEGIN@11
634113.87ms16.1msCompress::Zlib::gzFile::::gzeofCompress::Zlib::gzFile::gzeof
1112.44ms19.8msCompress::Zlib::::BEGIN@12 Compress::Zlib::BEGIN@12
1112.38ms17.5msCompress::Zlib::::BEGIN@13 Compress::Zlib::BEGIN@13
1274212.07ms2.15msCompress::Zlib::::_set_gzerr Compress::Zlib::_set_gzerr
321603µs14.2msCompress::Zlib::::gzopen Compress::Zlib::gzopen
32149µs345µsCompress::Zlib::gzFile::::gzcloseCompress::Zlib::gzFile::gzclose
217137µs37µsCompress::Zlib::::CORE:match Compress::Zlib::CORE:match (opcode)
11127µs100µsCompress::Zlib::::BEGIN@6 Compress::Zlib::BEGIN@6
11123µs295µsCompress::Zlib::::BEGIN@464 Compress::Zlib::BEGIN@464
11115µs34µsCompress::Zlib::::BEGIN@7 Compress::Zlib::BEGIN@7
11113µs16µsCompress::Zlib::::BEGIN@15 Compress::Zlib::BEGIN@15
11111µs39µsCompress::Zlib::::BEGIN@8 Compress::Zlib::BEGIN@8
11110µs21µsCompress::Zlib::::BEGIN@16 Compress::Zlib::BEGIN@16
11110µs12µsCompress::Zlib::::BEGIN@17 Compress::Zlib::BEGIN@17
1119µs44µsCompress::Zlib::::BEGIN@49 Compress::Zlib::BEGIN@49
1118µs64µsCompress::Zlib::::BEGIN@48 Compress::Zlib::BEGIN@48
1118µs47µsCompress::Zlib::::BEGIN@50 Compress::Zlib::BEGIN@50
1118µs43µsCompress::Zlib::::BEGIN@51 Compress::Zlib::BEGIN@51
1117µs7µsCompress::Zlib::::BEGIN@44 Compress::Zlib::BEGIN@44
2117µs7µsCompress::Zlib::gzFile::::gzerrorCompress::Zlib::gzFile::gzerror
0000s0sCompress::Zlib::::_removeGzipHeader Compress::Zlib::_removeGzipHeader
0000s0sCompress::Zlib::::_ret_gun_error Compress::Zlib::_ret_gun_error
0000s0sCompress::Zlib::::_set_gzerr_undef Compress::Zlib::_set_gzerr_undef
0000s0sCompress::Zlib::::compress Compress::Zlib::compress
0000s0sCompress::Zlib::::deflateInit Compress::Zlib::deflateInit
0000s0sCompress::Zlib::gzFile::::gzflushCompress::Zlib::gzFile::gzflush
0000s0sCompress::Zlib::gzFile::::gzreadlineCompress::Zlib::gzFile::gzreadline
0000s0sCompress::Zlib::gzFile::::gzseekCompress::Zlib::gzFile::gzseek
0000s0sCompress::Zlib::gzFile::::gzsetparamsCompress::Zlib::gzFile::gzsetparams
0000s0sCompress::Zlib::gzFile::::gztellCompress::Zlib::gzFile::gztell
0000s0sCompress::Zlib::gzFile::::gzwriteCompress::Zlib::gzFile::gzwrite
0000s0sCompress::Zlib::::inflateInit Compress::Zlib::inflateInit
0000s0sCompress::Zlib::::memGunzip Compress::Zlib::memGunzip
0000s0sCompress::Zlib::::memGzip Compress::Zlib::memGzip
0000s0sCompress::Zlib::::uncompress Compress::Zlib::uncompress
0000s0sZlib::OldDeflate::::deflate Zlib::OldDeflate::deflate
0000s0sZlib::OldDeflate::::flush Zlib::OldDeflate::flush
0000s0sZlib::OldInflate::::inflate Zlib::OldInflate::inflate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Compress::Zlib;
3
4110µsrequire 5.006 ;
511µsrequire Exporter;
6243µs2173µs
# spent 100µs (27+73) within Compress::Zlib::BEGIN@6 which was called: # once (27µs+73µs) by CPAN::has_inst at line 6
use Carp ;
# spent 100µs making 1 call to Compress::Zlib::BEGIN@6 # spent 73µs making 1 call to Exporter::import
7239µs253µs
# spent 34µs (15+19) within Compress::Zlib::BEGIN@7 which was called: # once (15µs+19µs) by CPAN::has_inst at line 7
use IO::Handle ;
# spent 34µs making 1 call to Compress::Zlib::BEGIN@7 # spent 19µs making 1 call to Exporter::import
8240µs267µs
# spent 39µs (11+28) within Compress::Zlib::BEGIN@8 which was called: # once (11µs+28µs) by CPAN::has_inst at line 8
use Scalar::Util qw(dualvar);
# spent 39µs making 1 call to Compress::Zlib::BEGIN@8 # spent 28µs making 1 call to Exporter::import
9
103822µs315.2ms
# spent 15.1ms (7.38+7.67) within Compress::Zlib::BEGIN@10 which was called: # once (7.38ms+7.67ms) by CPAN::has_inst at line 10
use IO::Compress::Base::Common 2.074 ;
# spent 15.1ms making 1 call to Compress::Zlib::BEGIN@10 # spent 139µs making 1 call to Exporter::import # spent 15µs making 1 call to version::_VERSION
113642µs38.17ms
# spent 7.93ms (4.57+3.36) within Compress::Zlib::BEGIN@11 which was called: # once (4.57ms+3.36ms) by CPAN::has_inst at line 11
use Compress::Raw::Zlib 2.074 ;
# spent 7.93ms making 1 call to Compress::Zlib::BEGIN@11 # spent 224µs making 1 call to Exporter::import # spent 14µs making 1 call to version::_VERSION
123524µs319.8ms
# spent 19.8ms (2.44+17.3) within Compress::Zlib::BEGIN@12 which was called: # once (2.44ms+17.3ms) by CPAN::has_inst at line 12
use IO::Compress::Gzip 2.074 ;
# spent 19.8ms making 1 call to Compress::Zlib::BEGIN@12 # spent 24µs making 1 call to Exporter::import # spent 10µs making 1 call to version::_VERSION
133598µs317.6ms
# spent 17.5ms (2.38+15.2) within Compress::Zlib::BEGIN@13 which was called: # once (2.38ms+15.2ms) by CPAN::has_inst at line 13
use IO::Uncompress::Gunzip 2.074 ;
# spent 17.5ms making 1 call to Compress::Zlib::BEGIN@13 # spent 19µs making 1 call to Exporter::import # spent 10µs making 1 call to version::_VERSION
14
15231µs219µs
# spent 16µs (13+3) within Compress::Zlib::BEGIN@15 which was called: # once (13µs+3µs) by CPAN::has_inst at line 15
use strict ;
# spent 16µs making 1 call to Compress::Zlib::BEGIN@15 # spent 3µs making 1 call to strict::import
16228µs232µs
# spent 21µs (10+11) within Compress::Zlib::BEGIN@16 which was called: # once (10µs+11µs) by CPAN::has_inst at line 16
use warnings ;
# spent 21µs making 1 call to Compress::Zlib::BEGIN@16 # spent 11µs making 1 call to warnings::import
172149µs214µs
# spent 12µs (10+2) within Compress::Zlib::BEGIN@17 which was called: # once (10µs+2µs) by CPAN::has_inst at line 17
use bytes ;
# spent 12µs making 1 call to Compress::Zlib::BEGIN@17 # spent 2µs making 1 call to bytes::import
18our ($VERSION, $XS_VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
19
2010s$VERSION = '2.074';
2111µs$XS_VERSION = $VERSION;
22117µs$VERSION = eval $VERSION;
# spent 4µs executing statements in string eval
23
2419µs@ISA = qw(Exporter);
25# Items to export into callers namespace by default. Note: do not export
26# names by default without a very good reason. Use EXPORT_OK instead.
27# Do not simply export all your public functions/methods/constants.
2811µs@EXPORT = qw(
29 deflateInit inflateInit
30
31 compress uncompress
32
33 gzopen $gzerrno
34 );
35
36111µspush @EXPORT, @Compress::Raw::Zlib::EXPORT ;
37
3810s@EXPORT_OK = qw(memGunzip memGzip zlib_version);
3912µs%EXPORT_TAGS = (
40 ALL => \@EXPORT
41);
42
43BEGIN
44
# spent 7µs within Compress::Zlib::BEGIN@44 which was called: # once (7µs+0s) by CPAN::has_inst at line 46
{
4517µs *zlib_version = \&Compress::Raw::Zlib::zlib_version;
46132µs17µs}
# spent 7µs making 1 call to Compress::Zlib::BEGIN@44
47
48235µs2120µs
# spent 64µs (8+56) within Compress::Zlib::BEGIN@48 which was called: # once (8µs+56µs) by CPAN::has_inst at line 48
use constant FLAG_APPEND => 1 ;
# spent 64µs making 1 call to Compress::Zlib::BEGIN@48 # spent 56µs making 1 call to constant::import
49232µs279µs
# spent 44µs (9+35) within Compress::Zlib::BEGIN@49 which was called: # once (9µs+35µs) by CPAN::has_inst at line 49
use constant FLAG_CRC => 2 ;
# spent 44µs making 1 call to Compress::Zlib::BEGIN@49 # spent 35µs making 1 call to constant::import
50231µs286µs
# spent 47µs (8+39) within Compress::Zlib::BEGIN@50 which was called: # once (8µs+39µs) by CPAN::has_inst at line 50
use constant FLAG_ADLER => 4 ;
# spent 47µs making 1 call to Compress::Zlib::BEGIN@50 # spent 39µs making 1 call to constant::import
5122.71ms278µs
# spent 43µs (8+35) within Compress::Zlib::BEGIN@51 which was called: # once (8µs+35µs) by CPAN::has_inst at line 51
use constant FLAG_CONSUME_INPUT => 8 ;
# spent 43µs making 1 call to Compress::Zlib::BEGIN@51 # spent 35µs making 1 call to constant::import
52
53our (@my_z_errmsg);
54
5511µs@my_z_errmsg = (
56 "need dictionary", # Z_NEED_DICT 2
57 "stream end", # Z_STREAM_END 1
58 "", # Z_OK 0
59 "file error", # Z_ERRNO (-1)
60 "stream error", # Z_STREAM_ERROR (-2)
61 "data error", # Z_DATA_ERROR (-3)
62 "insufficient memory", # Z_MEM_ERROR (-4)
63 "buffer error", # Z_BUF_ERROR (-5)
64 "incompatible version",# Z_VERSION_ERROR(-6)
65 );
66
67
68sub _set_gzerr
69
# spent 2.15ms (2.07+75µs) within Compress::Zlib::_set_gzerr which was called 1274 times, avg 2µs/call: # 1271 times (2.03ms+75µs) by Compress::Zlib::_save_gzerr at line 104, avg 2µs/call # 3 times (41µs+0s) by Compress::Zlib::gzopen at line 134, avg 14µs/call
{
701274245µs my $value = shift ;
71
721274431µs1050µs if ($value == 0) {
# spent 40µs making 1 call to Compress::Raw::Zlib::AUTOLOAD # spent 10µs making 9 calls to Compress::Raw::Zlib::__ANON__[Compress/Raw/Zlib.pm:114], avg 1µs/call
731264267µs $Compress::Zlib::gzerrno = 0 ;
74 }
75 elsif ($value == Z_ERRNO() || $value > 2) {
76 $Compress::Zlib::gzerrno = $! ;
77 }
78 else {
791053µs1023µs $Compress::Zlib::gzerrno = dualvar($value+0, $my_z_errmsg[2 - $value]);
# spent 23µs making 10 calls to Scalar::Util::dualvar, avg 2µs/call
80 }
81
8212745.76ms return $value ;
83}
84
85sub _set_gzerr_undef
86{
87 _set_gzerr(@_);
88 return undef;
89}
90
91sub _save_gzerr
92
# spent 29.5ms (22.5+7.00) within Compress::Zlib::_save_gzerr which was called 1271 times, avg 23µs/call: # 634 times (8.60ms+2.65ms) by Compress::Zlib::gzFile::gzeof at line 269, avg 18µs/call # 632 times (13.8ms+4.21ms) by Compress::Zlib::gzFile::gzread at line 175, avg 29µs/call # 3 times (26µs+23µs) by Compress::Zlib::gzFile::gzclose at line 256, avg 16µs/call # 2 times (17µs+125µs) by Compress::Zlib::gzFile::gzread at line 170, avg 71µs/call
{
931271274µs my $gz = shift ;
941271177µs my $test_eof = shift ;
95
9612711.74ms12711.43ms my $value = $gz->errorNo() || 0 ;
# spent 1.43ms making 1271 calls to IO::Uncompress::Base::errorNo, avg 1µs/call
9712711.67ms12712.37ms my $eof = $gz->eof() ;
# spent 2.37ms making 1271 calls to IO::Uncompress::Base::eof, avg 2µs/call
98
991271933µs6341.10ms if ($test_eof) {
# spent 1.10ms making 634 calls to IO::Uncompress::Base::eof, avg 2µs/call
100 # gzread uses Z_STREAM_END to denote a successful end
101 $value = Z_STREAM_END() if $gz->eof() && $value == 0 ;
102 }
103
10412713.30ms12712.11ms _set_gzerr($value) ;
# spent 2.11ms making 1271 calls to Compress::Zlib::_set_gzerr, avg 2µs/call
105}
106
107sub gzopen($$)
108
# spent 14.2ms (603µs+13.6) within Compress::Zlib::gzopen which was called 3 times, avg 4.74ms/call: # 2 times (561µs+11.8ms) by CPAN::Tarzip::gtest at line 143 of CPAN/Tarzip.pm, avg 6.17ms/call # once (42µs+1.83ms) by CPAN::Tarzip::TIEHANDLE at line 187 of CPAN/Tarzip.pm
{
10936µs my ($file, $mode) = @_ ;
110
111313µs my $gz ;
1123167µs660µs my %defOpts = (Level => Z_DEFAULT_COMPRESSION(),
# spent 60µs making 6 calls to Compress::Raw::Zlib::__ANON__[Compress/Raw/Zlib.pm:114], avg 10µs/call
113 Strategy => Z_DEFAULT_STRATEGY(),
114 );
115
11631µs my $writing ;
117371µs314µs $writing = ! ($mode =~ /r/i) ;
# spent 14µs making 3 calls to Compress::Zlib::CORE:match, avg 5µs/call
118328µs35µs $writing = ($mode =~ /[wa]/i) ;
# spent 5µs making 3 calls to Compress::Zlib::CORE:match, avg 2µs/call
119
120315µs34µs $defOpts{Level} = $1 if $mode =~ /(\d)/;
# spent 4µs making 3 calls to Compress::Zlib::CORE:match, avg 1µs/call
121310µs32µs $defOpts{Strategy} = Z_FILTERED() if $mode =~ /f/i;
# spent 2µs making 3 calls to Compress::Zlib::CORE:match, avg 667ns/call
122311µs32µs $defOpts{Strategy} = Z_HUFFMAN_ONLY() if $mode =~ /h/i;
# spent 2µs making 3 calls to Compress::Zlib::CORE:match, avg 667ns/call
12339µs32µs $defOpts{Append} = 1 if $mode =~ /a/i;
# spent 2µs making 3 calls to Compress::Zlib::CORE:match, avg 667ns/call
124
125314µs my $infDef = $writing ? 'deflate' : 'inflate';
12632µs my @params = () ;
127
1283100µs6205µs croak "gzopen: file parameter is not a filehandle or filename"
# spent 137µs making 3 calls to IO::Compress::Base::Common::isaFilehandle, avg 46µs/call # spent 68µs making 3 calls to IO::Compress::Base::Common::isaFilename, avg 23µs/call
129 unless isaFilehandle $file || isaFilename $file ||
130 (ref $file && ref $file eq 'SCALAR');
131
132334µs38µs return undef unless $mode =~ /[rwa]/i ;
# spent 8µs making 3 calls to Compress::Zlib::CORE:match, avg 3µs/call
133
134325µs341µs _set_gzerr(0) ;
# spent 41µs making 3 calls to Compress::Zlib::_set_gzerr, avg 14µs/call
135
13630s if ($writing) {
137 $gz = new IO::Compress::Gzip($file, Minimal => 1, AutoClose => 1,
138 %defOpts)
139 or $Compress::Zlib::gzerrno = $IO::Compress::Gzip::GzipError;
140 }
141 else {
1423175µs313.3ms $gz = new IO::Uncompress::Gunzip($file,
# spent 13.3ms making 3 calls to IO::Uncompress::Gunzip::new, avg 4.42ms/call
143 Transparent => 1,
144 Append => 0,
145 AutoClose => 1,
146 MultiStream => 1,
147 Strict => 0)
148 or $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError;
149 }
150
151 return undef
15231µs if ! defined $gz ;
153
154345µs bless [$gz, $infDef], 'Compress::Zlib::gzFile';
155}
156
157sub Compress::Zlib::gzFile::gzread
158
# spent 162ms (5.62+156) within Compress::Zlib::gzFile::gzread which was called 634 times, avg 256µs/call: # 632 times (5.56ms+156ms) by CPAN::Tarzip::gtest at line 149 of CPAN/Tarzip.pm, avg 256µs/call # 2 times (61µs+257µs) by CPAN::Tarzip::gtest at line 147 of CPAN/Tarzip.pm, avg 159µs/call
{
159634123µs my $self = shift ;
160
161634315µs return _set_gzerr(Z_STREAM_ERROR())
162 if $self->[1] ne 'inflate';
163
164634191µs my $len = defined $_[1] ? $_[1] : 4096 ;
165
16663499µs my $gz = $self->[0] ;
167634915µs63416.1ms if ($self->gzeof() || $len == 0) {
# spent 16.1ms making 634 calls to Compress::Zlib::gzFile::gzeof, avg 25µs/call
168 # Zap the output buffer to match ver 1 behaviour.
16920s $_[0] = "" ;
17022µs2142µs _save_gzerr($gz, 1);
# spent 142µs making 2 calls to Compress::Zlib::_save_gzerr, avg 71µs/call
17125µs return 0 ;
172 }
173
174632902µs632122ms my $status = $gz->read($_[0], $len) ;
# spent 122ms making 632 calls to IO::Uncompress::Base::read, avg 193µs/call
175632816µs63218.0ms _save_gzerr($gz, 1);
# spent 18.0ms making 632 calls to Compress::Zlib::_save_gzerr, avg 29µs/call
1766321.20ms return $status ;
177}
178
179sub Compress::Zlib::gzFile::gzreadline
180{
181 my $self = shift ;
182
183 my $gz = $self->[0] ;
184 {
185 # Maintain backward compatibility with 1.x behaviour
186 # It didn't support $/, so this can't either.
187 local $/ = "\n" ;
188 $_[0] = $gz->getline() ;
189 }
190 _save_gzerr($gz, 1);
191 return defined $_[0] ? length $_[0] : 0 ;
192}
193
194sub Compress::Zlib::gzFile::gzwrite
195{
196 my $self = shift ;
197 my $gz = $self->[0] ;
198
199 return _set_gzerr(Z_STREAM_ERROR())
200 if $self->[1] ne 'deflate';
201
202 $] >= 5.008 and (utf8::downgrade($_[0], 1)
203 or croak "Wide character in gzwrite");
204
205 my $status = $gz->write($_[0]) ;
206 _save_gzerr($gz);
207 return $status ;
208}
209
210sub Compress::Zlib::gzFile::gztell
211{
212 my $self = shift ;
213 my $gz = $self->[0] ;
214 my $status = $gz->tell() ;
215 _save_gzerr($gz);
216 return $status ;
217}
218
219sub Compress::Zlib::gzFile::gzseek
220{
221 my $self = shift ;
222 my $offset = shift ;
223 my $whence = shift ;
224
225 my $gz = $self->[0] ;
226 my $status ;
227 eval { $status = $gz->seek($offset, $whence) ; };
228 if ($@)
229 {
230 my $error = $@;
231 $error =~ s/^.*: /gzseek: /;
232 $error =~ s/ at .* line \d+\s*$//;
233 croak $error;
234 }
235 _save_gzerr($gz);
236 return $status ;
237}
238
239sub Compress::Zlib::gzFile::gzflush
240{
241 my $self = shift ;
242 my $f = shift ;
243
244 my $gz = $self->[0] ;
245 my $status = $gz->flush($f) ;
246 my $err = _save_gzerr($gz);
247 return $status ? 0 : $err;
248}
249
250sub Compress::Zlib::gzFile::gzclose
251
# spent 345µs (49+296) within Compress::Zlib::gzFile::gzclose which was called 3 times, avg 115µs/call: # 2 times (33µs+200µs) by CPAN::Tarzip::gtest at line 157 of CPAN/Tarzip.pm, avg 116µs/call # once (16µs+96µs) by CPAN::Tarzip::DESTROY at line 236 of CPAN/Tarzip.pm
{
25232µs my $self = shift ;
25330s my $gz = $self->[0] ;
254
255334µs3247µs my $status = $gz->close() ;
# spent 247µs making 3 calls to IO::Uncompress::Base::close, avg 82µs/call
25637µs349µs my $err = _save_gzerr($gz);
# spent 49µs making 3 calls to Compress::Zlib::_save_gzerr, avg 16µs/call
257314µs return $status ? 0 : $err;
258}
259
260sub Compress::Zlib::gzFile::gzeof
261
# spent 16.1ms (3.87+12.3) within Compress::Zlib::gzFile::gzeof which was called 634 times, avg 25µs/call: # 634 times (3.87ms+12.3ms) by Compress::Zlib::gzFile::gzread at line 167, avg 25µs/call
{
262634125µs my $self = shift ;
263634116µs my $gz = $self->[0] ;
264
265634159µs return 0
266 if $self->[1] ne 'inflate';
267
268634790µs6341.02ms my $status = $gz->eof() ;
# spent 1.02ms making 634 calls to IO::Uncompress::Base::eof, avg 2µs/call
269634631µs63411.3ms _save_gzerr($gz);
# spent 11.3ms making 634 calls to Compress::Zlib::_save_gzerr, avg 18µs/call
2706341.26ms return $status ;
271}
272
273sub Compress::Zlib::gzFile::gzsetparams
274{
275 my $self = shift ;
276 croak "Usage: Compress::Zlib::gzFile::gzsetparams(file, level, strategy)"
277 unless @_ eq 2 ;
278
279 my $gz = $self->[0] ;
280 my $level = shift ;
281 my $strategy = shift;
282
283 return _set_gzerr(Z_STREAM_ERROR())
284 if $self->[1] ne 'deflate';
285
286 my $status = *$gz->{Compress}->deflateParams(-Level => $level,
287 -Strategy => $strategy);
288 _save_gzerr($gz);
289 return $status ;
290}
291
292sub Compress::Zlib::gzFile::gzerror
293
# spent 7µs within Compress::Zlib::gzFile::gzerror which was called 2 times, avg 4µs/call: # 2 times (7µs+0s) by CPAN::Tarzip::gtest at line 151 of CPAN/Tarzip.pm, avg 4µs/call
{
29420s my $self = shift ;
29522µs my $gz = $self->[0] ;
296
29727µs return $Compress::Zlib::gzerrno ;
298}
299
300
301sub compress($;$)
302{
303 my ($x, $output, $err, $in) =('', '', '', '') ;
304
305 if (ref $_[0] ) {
306 $in = $_[0] ;
307 croak "not a scalar reference" unless ref $in eq 'SCALAR' ;
308 }
309 else {
310 $in = \$_[0] ;
311 }
312
313 $] >= 5.008 and (utf8::downgrade($$in, 1)
314 or croak "Wide character in compress");
315
316 my $level = (@_ == 2 ? $_[1] : Z_DEFAULT_COMPRESSION() );
317
318 $x = Compress::Raw::Zlib::_deflateInit(FLAG_APPEND,
319 $level,
320 Z_DEFLATED,
321 MAX_WBITS,
322 MAX_MEM_LEVEL,
323 Z_DEFAULT_STRATEGY,
324 4096,
325 '')
326 or return undef ;
327
328 $err = $x->deflate($in, $output) ;
329 return undef unless $err == Z_OK() ;
330
331 $err = $x->flush($output) ;
332 return undef unless $err == Z_OK() ;
333
334 return $output ;
335}
336
337sub uncompress($)
338{
339 my ($output, $in) =('', '') ;
340
341 if (ref $_[0] ) {
342 $in = $_[0] ;
343 croak "not a scalar reference" unless ref $in eq 'SCALAR' ;
344 }
345 else {
346 $in = \$_[0] ;
347 }
348
349 $] >= 5.008 and (utf8::downgrade($$in, 1)
350 or croak "Wide character in uncompress");
351
352 my ($obj, $status) = Compress::Raw::Zlib::_inflateInit(0,
353 MAX_WBITS, 4096, "") ;
354
355 $status == Z_OK
356 or return undef;
357
358 $obj->inflate($in, $output) == Z_STREAM_END
359 or return undef;
360
361 return $output;
362}
363
364sub deflateInit(@)
365{
366 my ($got) = ParseParameters(0,
367 {
368 'bufsize' => [IO::Compress::Base::Common::Parse_unsigned, 4096],
369 'level' => [IO::Compress::Base::Common::Parse_signed, Z_DEFAULT_COMPRESSION()],
370 'method' => [IO::Compress::Base::Common::Parse_unsigned, Z_DEFLATED()],
371 'windowbits' => [IO::Compress::Base::Common::Parse_signed, MAX_WBITS()],
372 'memlevel' => [IO::Compress::Base::Common::Parse_unsigned, MAX_MEM_LEVEL()],
373 'strategy' => [IO::Compress::Base::Common::Parse_unsigned, Z_DEFAULT_STRATEGY()],
374 'dictionary' => [IO::Compress::Base::Common::Parse_any, ""],
375 }, @_ ) ;
376
377 croak "Compress::Zlib::deflateInit: Bufsize must be >= 1, you specified " .
378 $got->getValue('bufsize')
379 unless $got->getValue('bufsize') >= 1;
380
381 my $obj ;
382
383 my $status = 0 ;
384 ($obj, $status) =
385 Compress::Raw::Zlib::_deflateInit(0,
386 $got->getValue('level'),
387 $got->getValue('method'),
388 $got->getValue('windowbits'),
389 $got->getValue('memlevel'),
390 $got->getValue('strategy'),
391 $got->getValue('bufsize'),
392 $got->getValue('dictionary')) ;
393
394 my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldDeflate" : undef) ;
395 return wantarray ? ($x, $status) : $x ;
396}
397
398sub inflateInit(@)
399{
400 my ($got) = ParseParameters(0,
401 {
402 'bufsize' => [IO::Compress::Base::Common::Parse_unsigned, 4096],
403 'windowbits' => [IO::Compress::Base::Common::Parse_signed, MAX_WBITS()],
404 'dictionary' => [IO::Compress::Base::Common::Parse_any, ""],
405 }, @_) ;
406
407
408 croak "Compress::Zlib::inflateInit: Bufsize must be >= 1, you specified " .
409 $got->getValue('bufsize')
410 unless $got->getValue('bufsize') >= 1;
411
412 my $status = 0 ;
413 my $obj ;
414 ($obj, $status) = Compress::Raw::Zlib::_inflateInit(FLAG_CONSUME_INPUT,
415 $got->getValue('windowbits'),
416 $got->getValue('bufsize'),
417 $got->getValue('dictionary')) ;
418
419 my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldInflate" : undef) ;
420
421 wantarray ? ($x, $status) : $x ;
422}
423
424package Zlib::OldDeflate ;
425
426our (@ISA);
42718µs@ISA = qw(Compress::Raw::Zlib::deflateStream);
428
429
430sub deflate
431{
432 my $self = shift ;
433 my $output ;
434
435 my $status = $self->SUPER::deflate($_[0], $output) ;
436 wantarray ? ($output, $status) : $output ;
437}
438
439sub flush
440{
441 my $self = shift ;
442 my $output ;
443 my $flag = shift || Compress::Zlib::Z_FINISH();
444 my $status = $self->SUPER::flush($output, $flag) ;
445
446 wantarray ? ($output, $status) : $output ;
447}
448
449package Zlib::OldInflate ;
450
451our (@ISA);
45217µs@ISA = qw(Compress::Raw::Zlib::inflateStream);
453
454sub inflate
455{
456 my $self = shift ;
457 my $output ;
458 my $status = $self->SUPER::inflate($_[0], $output) ;
459 wantarray ? ($output, $status) : $output ;
460}
461
462package Compress::Zlib ;
463
4643869µs3567µs
# spent 295µs (23+272) within Compress::Zlib::BEGIN@464 which was called: # once (23µs+272µs) by CPAN::has_inst at line 464
use IO::Compress::Gzip::Constants 2.074 ;
# spent 295µs making 1 call to Compress::Zlib::BEGIN@464 # spent 260µs making 1 call to Exporter::import # spent 12µs making 1 call to version::_VERSION
465
466sub memGzip($)
467{
468 _set_gzerr(0);
469 my $x = Compress::Raw::Zlib::_deflateInit(FLAG_APPEND|FLAG_CRC,
470 Z_BEST_COMPRESSION,
471 Z_DEFLATED,
472 -MAX_WBITS(),
473 MAX_MEM_LEVEL,
474 Z_DEFAULT_STRATEGY,
475 4096,
476 '')
477 or return undef ;
478
479 # if the deflation buffer isn't a reference, make it one
480 my $string = (ref $_[0] ? $_[0] : \$_[0]) ;
481
482 $] >= 5.008 and (utf8::downgrade($$string, 1)
483 or croak "Wide character in memGzip");
484
485 my $out;
486 my $status ;
487
488 $x->deflate($string, $out) == Z_OK
489 or return undef ;
490
491 $x->flush($out) == Z_OK
492 or return undef ;
493
494 return IO::Compress::Gzip::Constants::GZIP_MINIMUM_HEADER .
495 $out .
496 pack("V V", $x->crc32(), $x->total_in());
497}
498
499
500sub _removeGzipHeader($)
501{
502 my $string = shift ;
503
504 return Z_DATA_ERROR()
505 if length($$string) < GZIP_MIN_HEADER_SIZE ;
506
507 my ($magic1, $magic2, $method, $flags, $time, $xflags, $oscode) =
508 unpack ('CCCCVCC', $$string);
509
510 return Z_DATA_ERROR()
511 unless $magic1 == GZIP_ID1 and $magic2 == GZIP_ID2 and
512 $method == Z_DEFLATED() and !($flags & GZIP_FLG_RESERVED) ;
513 substr($$string, 0, GZIP_MIN_HEADER_SIZE) = '' ;
514
515 # skip extra field
516 if ($flags & GZIP_FLG_FEXTRA)
517 {
518 return Z_DATA_ERROR()
519 if length($$string) < GZIP_FEXTRA_HEADER_SIZE ;
520
521 my ($extra_len) = unpack ('v', $$string);
522 $extra_len += GZIP_FEXTRA_HEADER_SIZE;
523 return Z_DATA_ERROR()
524 if length($$string) < $extra_len ;
525
526 substr($$string, 0, $extra_len) = '';
527 }
528
529 # skip orig name
530 if ($flags & GZIP_FLG_FNAME)
531 {
532 my $name_end = index ($$string, GZIP_NULL_BYTE);
533 return Z_DATA_ERROR()
534 if $name_end == -1 ;
535 substr($$string, 0, $name_end + 1) = '';
536 }
537
538 # skip comment
539 if ($flags & GZIP_FLG_FCOMMENT)
540 {
541 my $comment_end = index ($$string, GZIP_NULL_BYTE);
542 return Z_DATA_ERROR()
543 if $comment_end == -1 ;
544 substr($$string, 0, $comment_end + 1) = '';
545 }
546
547 # skip header crc
548 if ($flags & GZIP_FLG_FHCRC)
549 {
550 return Z_DATA_ERROR()
551 if length ($$string) < GZIP_FHCRC_SIZE ;
552 substr($$string, 0, GZIP_FHCRC_SIZE) = '';
553 }
554
555 return Z_OK();
556}
557
558sub _ret_gun_error
559{
560 $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError;
561 return undef;
562}
563
564
565sub memGunzip($)
566{
567 # if the buffer isn't a reference, make it one
568 my $string = (ref $_[0] ? $_[0] : \$_[0]);
569
570 $] >= 5.008 and (utf8::downgrade($$string, 1)
571 or croak "Wide character in memGunzip");
572
573 _set_gzerr(0);
574
575 my $status = _removeGzipHeader($string) ;
576 $status == Z_OK()
577 or return _set_gzerr_undef($status);
578
579 my $bufsize = length $$string > 4096 ? length $$string : 4096 ;
580 my $x = Compress::Raw::Zlib::_inflateInit(FLAG_CRC | FLAG_CONSUME_INPUT,
581 -MAX_WBITS(), $bufsize, '')
582 or return _ret_gun_error();
583
584 my $output = '' ;
585 $status = $x->inflate($string, $output);
586
587 if ( $status == Z_OK() )
588 {
589 _set_gzerr(Z_DATA_ERROR());
590 return undef;
591 }
592
593 return _ret_gun_error()
594 if ($status != Z_STREAM_END());
595
596 if (length $$string >= 8)
597 {
598 my ($crc, $len) = unpack ("VV", substr($$string, 0, 8));
599 substr($$string, 0, 8) = '';
600 return _set_gzerr_undef(Z_DATA_ERROR())
601 unless $len == length($output) and
602 $crc == Compress::Raw::Zlib::crc32($output);
603 }
604 else
605 {
606 $$string = '';
607 }
608
609 return $output;
610}
611
612# Autoload methods go after __END__, and are processed by the autosplit program.
613
614112µs1;
615__END__
 
# spent 37µs within Compress::Zlib::CORE:match which was called 21 times, avg 2µs/call: # 3 times (14µs+0s) by Compress::Zlib::gzopen at line 117, avg 5µs/call # 3 times (8µs+0s) by Compress::Zlib::gzopen at line 132, avg 3µs/call # 3 times (5µs+0s) by Compress::Zlib::gzopen at line 118, avg 2µs/call # 3 times (4µs+0s) by Compress::Zlib::gzopen at line 120, avg 1µs/call # 3 times (2µs+0s) by Compress::Zlib::gzopen at line 123, avg 667ns/call # 3 times (2µs+0s) by Compress::Zlib::gzopen at line 122, avg 667ns/call # 3 times (2µs+0s) by Compress::Zlib::gzopen at line 121, avg 667ns/call
sub Compress::Zlib::CORE:match; # opcode