← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:37 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Compress/Bzip2.pm
StatementsExecuted 61 statements in 4.09ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.11ms1.15msCompress::Bzip2::::BEGIN@20Compress::Bzip2::BEGIN@20
11137µs37µsCompress::Bzip2::::BEGIN@14Compress::Bzip2::BEGIN@14
11113µs131µsCompress::Bzip2::::BEGIN@146Compress::Bzip2::BEGIN@146
11111µs63µsCompress::Bzip2::::BEGIN@141Compress::Bzip2::BEGIN@141
11111µs692µsCompress::Bzip2::::BEGIN@21Compress::Bzip2::BEGIN@21
11111µs109µsCompress::Bzip2::::BEGIN@24Compress::Bzip2::BEGIN@24
11111µs66µsCompress::Bzip2::::BEGIN@19Compress::Bzip2::BEGIN@19
1119µs94µsCompress::Bzip2::::BEGIN@143Compress::Bzip2::BEGIN@143
1119µs11µsCompress::Bzip2::::BEGIN@16Compress::Bzip2::BEGIN@16
1119µs25µsCompress::Bzip2::::BEGIN@175Compress::Bzip2::BEGIN@175
1118µs81µsCompress::Bzip2::::BEGIN@153Compress::Bzip2::BEGIN@153
1118µs63µsCompress::Bzip2::::BEGIN@150Compress::Bzip2::BEGIN@150
1117µs54µsCompress::Bzip2::::BEGIN@156Compress::Bzip2::BEGIN@156
1117µs14µsCompress::Bzip2::::BEGIN@17Compress::Bzip2::BEGIN@17
1116µs29µsCompress::Bzip2::::BEGIN@158Compress::Bzip2::BEGIN@158
1116µs28µsCompress::Bzip2::::BEGIN@160Compress::Bzip2::BEGIN@160
0000s0sCompress::Bzip2::::AUTOLOADCompress::Bzip2::AUTOLOAD
0000s0sCompress::Bzip2::::__ANON__[:181]Compress::Bzip2::__ANON__[:181]
0000s0sCompress::Bzip2::::_bzerror2gzerrorCompress::Bzip2::_bzerror2gzerror
0000s0sCompress::Bzip2::::_check_statCompress::Bzip2::_check_stat
0000s0sCompress::Bzip2::::_process_filesCompress::Bzip2::_process_files
0000s0sCompress::Bzip2::::_set_stat_from_snapshotCompress::Bzip2::_set_stat_from_snapshot
0000s0sCompress::Bzip2::::_stat_snapshotCompress::Bzip2::_stat_snapshot
0000s0sCompress::Bzip2::::_writefileopenCompress::Bzip2::_writefileopen
0000s0sCompress::Bzip2::::addCompress::Bzip2::add
0000s0sCompress::Bzip2::::adler32Compress::Bzip2::adler32
0000s0sCompress::Bzip2::::bunzip2Compress::Bzip2::bunzip2
0000s0sCompress::Bzip2::::bzcatCompress::Bzip2::bzcat
0000s0sCompress::Bzip2::::bzip2Compress::Bzip2::bzip2
0000s0sCompress::Bzip2::::crc32Compress::Bzip2::crc32
0000s0sCompress::Bzip2::::deflateCompress::Bzip2::deflate
0000s0sCompress::Bzip2::::deflateInitCompress::Bzip2::deflateInit
0000s0sCompress::Bzip2::::deflateParamsCompress::Bzip2::deflateParams
0000s0sCompress::Bzip2::::dict_adlerCompress::Bzip2::dict_adler
0000s0sCompress::Bzip2::::errorCompress::Bzip2::error
0000s0sCompress::Bzip2::::finishCompress::Bzip2::finish
0000s0sCompress::Bzip2::::flushCompress::Bzip2::flush
0000s0sCompress::Bzip2::::gzcloseCompress::Bzip2::gzclose
0000s0sCompress::Bzip2::::gzeofCompress::Bzip2::gzeof
0000s0sCompress::Bzip2::::gzerrorCompress::Bzip2::gzerror
0000s0sCompress::Bzip2::::gzflushCompress::Bzip2::gzflush
0000s0sCompress::Bzip2::::gzopenCompress::Bzip2::gzopen
0000s0sCompress::Bzip2::::gzreadCompress::Bzip2::gzread
0000s0sCompress::Bzip2::::gzreadlineCompress::Bzip2::gzreadline
0000s0sCompress::Bzip2::::gzsetparamsCompress::Bzip2::gzsetparams
0000s0sCompress::Bzip2::::gzwriteCompress::Bzip2::gzwrite
0000s0sCompress::Bzip2::::inflateCompress::Bzip2::inflate
0000s0sCompress::Bzip2::::inflateInitCompress::Bzip2::inflateInit
0000s0sCompress::Bzip2::::inflateSyncCompress::Bzip2::inflateSync
0000s0sCompress::Bzip2::::input_sizeCompress::Bzip2::input_size
0000s0sCompress::Bzip2::::memGunzipCompress::Bzip2::memGunzip
0000s0sCompress::Bzip2::::memGzipCompress::Bzip2::memGzip
0000s0sCompress::Bzip2::::msgCompress::Bzip2::msg
0000s0sCompress::Bzip2::::output_sizeCompress::Bzip2::output_size
0000s0sCompress::Bzip2::::uncompressCompress::Bzip2::uncompress
0000s0sCompress::Bzip2::::versionCompress::Bzip2::version
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# File : Bzip2.pm
2# Author : Rob Janes
3# Created : 14 April 2005
4# Modified : 9 Aug 2005
5# Version : 2.09
6#
7# Copyright (c) 2005 Rob Janes. All rights reserved.
8# This program is free software; you can redistribute it and/or
9# modify it under the same terms as Perl itself.
10#
11
12package Compress::Bzip2;
13
14346µs137µs
# spent 37µs within Compress::Bzip2::BEGIN@14 which was called: # once (37µs+0s) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 14
use 5.006;
# spent 37µs making 1 call to Compress::Bzip2::BEGIN@14
15
16316µs213µs
# spent 11µs (9+2) within Compress::Bzip2::BEGIN@16 which was called: # once (9µs+2µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 16
use strict;
# spent 11µs making 1 call to Compress::Bzip2::BEGIN@16 # spent 2µs making 1 call to strict::import
17316µs221µs
# spent 14µs (7+7) within Compress::Bzip2::BEGIN@17 which was called: # once (7µs+7µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 17
use warnings;
# spent 14µs making 1 call to Compress::Bzip2::BEGIN@17 # spent 7µs making 1 call to warnings::import
18
19322µs2121µs
# spent 66µs (11+55) within Compress::Bzip2::BEGIN@19 which was called: # once (11µs+55µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 19
use Carp;
# spent 66µs making 1 call to Compress::Bzip2::BEGIN@19 # spent 55µs making 1 call to Exporter::import
2031.10ms21.18ms
# spent 1.15ms (1.11+32µs) within Compress::Bzip2::BEGIN@20 which was called: # once (1.11ms+32µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 20
use Getopt::Std;
# spent 1.15ms making 1 call to Compress::Bzip2::BEGIN@20 # spent 32µs making 1 call to Exporter::import
21327µs21.37ms
# spent 692µs (11+680) within Compress::Bzip2::BEGIN@21 which was called: # once (11µs+680µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 21
use Fcntl qw(:DEFAULT :mode);
# spent 692µs making 1 call to Compress::Bzip2::BEGIN@21 # spent 680µs making 1 call to Exporter::import
22
2311µsrequire Exporter;
243193µs2207µs
# spent 109µs (11+98) within Compress::Bzip2::BEGIN@24 which was called: # once (11µs+98µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 24
use AutoLoader;
# spent 109µs making 1 call to Compress::Bzip2::BEGIN@24 # spent 98µs making 1 call to AutoLoader::import
25
26110µsour @ISA = qw(Exporter);
27
28# Items to export into callers namespace by default. Note: do not export
29# names by default without a very good reason. Use EXPORT_OK instead.
30# Do not simply export all your public functions/methods/constants.
31
32# This allows declaration use Compress::Bzip2 ':all';
33# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
34# will save memory.
35112µsour %EXPORT_TAGS =
36 ( 'constants' => [ qw(
37 BZ_CONFIG_ERROR
38 BZ_DATA_ERROR
39 BZ_DATA_ERROR_MAGIC
40 BZ_FINISH
41 BZ_FINISH_OK
42 BZ_FLUSH
43 BZ_FLUSH_OK
44 BZ_IO_ERROR
45 BZ_MAX_UNUSED
46 BZ_MEM_ERROR
47 BZ_OK
48 BZ_OUTBUFF_FULL
49 BZ_PARAM_ERROR
50 BZ_RUN
51 BZ_RUN_OK
52 BZ_SEQUENCE_ERROR
53 BZ_STREAM_END
54 BZ_UNEXPECTED_EOF
55 ) ],
56
57 'utilities' => [ qw(
58 &bzopen
59 &bzinflateInit
60 &bzdeflateInit
61 &memBzip &memBunzip
62 &compress &decompress
63 &bzip2 &bunzip2
64 &bzlibversion
65 $bzerrno
66 ) ],
67
68 'bzip1' => [ qw(
69 &compress
70 &decompress
71 &compress_init
72 &decompress_init
73 &version
74 ) ],
75
76 'gzip' => [ qw(
77 &gzopen
78 &inflateInit
79 &deflateInit
80 &compress &uncompress
81 &adler32 &crc32
82
83 ZLIB_VERSION
84
85 $gzerrno
86
87 Z_OK
88 Z_STREAM_END
89 Z_NEED_DICT
90 Z_ERRNO
91 Z_STREAM_ERROR
92 Z_DATA_ERROR
93 Z_MEM_ERROR
94 Z_BUF_ERROR
95 Z_VERSION_ERROR
96
97 Z_NO_FLUSH
98 Z_PARTIAL_FLUSH
99 Z_SYNC_FLUSH
100 Z_FULL_FLUSH
101 Z_FINISH
102 Z_BLOCK
103
104 Z_NO_COMPRESSION
105 Z_BEST_SPEED
106 Z_BEST_COMPRESSION
107 Z_DEFAULT_COMPRESSION
108
109 Z_FILTERED
110 Z_HUFFMAN_ONLY
111 Z_RLE
112 Z_DEFAULT_STRATEGY
113
114 Z_BINARY
115 Z_ASCII
116 Z_UNKNOWN
117
118 Z_DEFLATED
119 Z_NULL
120 ) ],
121 );
122
123our @EXPORT_OK = ( @{ $EXPORT_TAGS{'utilities'} },
124 @{ $EXPORT_TAGS{'constants'} },
125 @{ $EXPORT_TAGS{'bzip1'} },
126120µs @{ $EXPORT_TAGS{'gzip'} },
127 );
128
129111µs$EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
130
131114µsour @EXPORT = ( @{ $EXPORT_TAGS{'utilities'} }, @{ $EXPORT_TAGS{'constants'} } );
132
1331400nsour $VERSION = "2.09";
134
1351200nsour $bzerrno = "";
1361100nsour $gzerrno;
1371900ns*gzerrno = \$bzerrno;
138
139# Zlib compatibility
140##
141332µs2114µs
# spent 63µs (11+51) within Compress::Bzip2::BEGIN@141 which was called: # once (11µs+51µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 141
use constant ZLIB_VERSION => '1.x';
# spent 63µs making 1 call to Compress::Bzip2::BEGIN@141 # spent 51µs making 1 call to constant::import
142# allowed flush values
143184µs
# spent 94µs (9+84) within Compress::Bzip2::BEGIN@143 which was called: # once (9µs+84µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 144
use constant { Z_NO_FLUSH => 0, Z_PARTIAL_FLUSH => 1, Z_SYNC_FLUSH => 2,
# spent 84µs making 1 call to constant::import
144336µs194µs Z_FULL_FLUSH => 3, Z_FINISH => 4, Z_BLOCK => 5 };
# spent 94µs making 1 call to Compress::Bzip2::BEGIN@143
145# return codes for functions, positive normal, negative error
1461118µs
# spent 131µs (13+117) within Compress::Bzip2::BEGIN@146 which was called: # once (13µs+117µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 148
use constant { Z_OK => 0, Z_STREAM_END => 1, Z_NEED_DICT => 2, Z_ERRNO => -1,
# spent 118µs making 1 call to constant::import
147 Z_STREAM_ERROR => -2, Z_DATA_ERROR => -3, Z_MEM_ERROR => -4,
148334µs1131µs Z_BUF_ERROR => -5, Z_VERSION_ERROR => -6 };
# spent 131µs making 1 call to Compress::Bzip2::BEGIN@146
149# compression levels
150154µs
# spent 63µs (8+54) within Compress::Bzip2::BEGIN@150 which was called: # once (8µs+54µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 151
use constant { Z_NO_COMPRESSION => 0, Z_BEST_SPEED => 1,
# spent 54µs making 1 call to constant::import
151325µs163µs Z_BEST_COMPRESSION => 9, Z_DEFAULT_COMPRESSION => -1 };
# spent 63µs making 1 call to Compress::Bzip2::BEGIN@150
152# compression strategy, for deflateInit
153172µs
# spent 81µs (8+72) within Compress::Bzip2::BEGIN@153 which was called: # once (8µs+72µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 154
use constant { Z_FILTERED => 1, Z_HUFFMAN_ONLY => 2, Z_RLE => 3,
# spent 72µs making 1 call to constant::import
154324µs181µs Z_DEFAULT_STRATEGY => 0 };
# spent 81µs making 1 call to Compress::Bzip2::BEGIN@153
155# possible values of data_type (inflate)
156321µs2100µs
# spent 54µs (7+47) within Compress::Bzip2::BEGIN@156 which was called: # once (7µs+47µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 156
use constant { Z_BINARY => 0, Z_ASCII => 1, Z_UNKNOWN => 2 };
# spent 54µs making 1 call to Compress::Bzip2::BEGIN@156 # spent 47µs making 1 call to constant::import
157# the deflate compression method
158318µs251µs
# spent 29µs (6+23) within Compress::Bzip2::BEGIN@158 which was called: # once (6µs+23µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 158
use constant Z_DEFLATED => 8;
# spent 29µs making 1 call to Compress::Bzip2::BEGIN@158 # spent 23µs making 1 call to constant::import
159# for initialization
160382µs251µs
# spent 28µs (6+22) within Compress::Bzip2::BEGIN@160 which was called: # once (6µs+22µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 160
use constant Z_NULL => 0;
# spent 28µs making 1 call to Compress::Bzip2::BEGIN@160 # spent 22µs making 1 call to constant::import
161
162## gzopen, $gzerror, gzerror, gzclose, gzreadline, gzwrite
163
164sub AUTOLOAD {
165 # This AUTOLOAD is used to 'autoload' constants from the constant()
166 # XS function.
167
168 my $constname;
169 our $AUTOLOAD;
170 ($constname = $AUTOLOAD) =~ s/.*:://;
171 croak "&Compress::Bzip2::constant not defined" if $constname eq 'constant';
172 my ($error, $val) = constant($constname);
173 if ($error) { croak $error; }
174 {
17531.98ms241µs
# spent 25µs (9+16) within Compress::Bzip2::BEGIN@175 which was called: # once (9µs+16µs) by Tapper::Schema::ReportsDB::Result::ReportFile::BEGIN@13 at line 175
no strict 'refs';
# spent 25µs making 1 call to Compress::Bzip2::BEGIN@175 # spent 16µs making 1 call to strict::unimport
176 # Fixed between 5.005_53 and 5.005_61
177#XXX if ($] >= 5.00561) {
178#XXX *$AUTOLOAD = sub () { $val };
179#XXX }
180#XXX else {
181 *$AUTOLOAD = sub { $val };
182#XXX }
183 }
184 goto &$AUTOLOAD;
185}
186
1871800nsrequire XSLoader;
1881330µs1320µsXSLoader::load('Compress::Bzip2', $VERSION);
# spent 320µs making 1 call to XSLoader::load
189
190#bootstrap Compress::Bzip2 $VERSION;
191
192##############################################################################
193## file compress uncompress commands
194
195sub _writefileopen ( $$;$ ) {
196 ## open a protected file for write
197 my ( $handle, $filename, $force ) = @_;
198
199 if ( sysopen($handle, $filename, $force ? O_WRONLY|O_CREAT|O_TRUNC : O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR) ) {
200 $_[0] = $handle if !defined($_[0]);
201 return $handle;
202 }
203
204 return undef;
205}
206
207sub _stat_snapshot ( $ ) {
208 my ( $filename ) = @_;
209 return undef if !defined($filename);
210
211 my @stats = stat $filename;
212 if (!@stats) {
213 warn "stat of $filename failed: $!\n" if !@stats;
214 return undef;
215 }
216
217 return \@stats;
218}
219
220sub _check_stat ( $$;$ ) {
221 my ( $filename, $statsnap, $force ) = @_;
222
223 if ( !defined($statsnap) || (ref($statsnap) eq 'ARRAY' && @$statsnap == 0) ) {
224 $statsnap = _stat_snapshot( $filename );
225 if ( $statsnap ) {
226 if ( @_>1 ) {
227 if ( !defined($_[1]) ) {
228 $_[1] = $statsnap;
229 }
230 elsif ( ref($_[1]) eq 'ARRAY' && @{ $_[1] } == 0 ) {
231 @{ $_[1] } = @$statsnap;
232 }
233 }
234 }
235 else {
236 return undef;
237 }
238 }
239
240 if ( S_ISDIR( $statsnap->[2] ) ) {
241 bz_seterror( &BZ_IO_ERROR, "file $filename is a directory" );
242 return 0;
243 }
244
245 if ( !S_ISREG( $statsnap->[2] ) ) {
246 bz_seterror( &BZ_IO_ERROR, "file $filename is not a normal file" );
247 return 0;
248 }
249
250 if ( !$force && S_ISLNK( $statsnap->[2] ) ) {
251 bz_seterror( &BZ_IO_ERROR, "file $filename is a symlink" );
252 return 0;
253 }
254
255 if ( !$force && $statsnap->[3] > 1 ) {
256 bz_seterror( &BZ_IO_ERROR, "file $filename has too many hard links" );
257 return 0;
258 }
259
260 return 1;
261}
262
263sub _set_stat_from_snapshot ( $$ ) {
264 my ( $filename, $statsnap ) = @_;
265
266 if ( !chmod( S_IMODE( $statsnap->[2] ), $filename ) ) {
267 bz_seterror( &BZ_IO_ERROR, "chmod ".sprintf('%03o', S_IMODE( $statsnap->[2] ))." $filename failed: $!" );
268 return undef;
269 }
270
271 if ( !utime @$statsnap[8,9], $filename ) {
272 bz_seterror( &BZ_IO_ERROR,
273 "utime " . join(' ',map { strftime('%Y-%m-%d %H:%M:%S', localtime $_) } @$statsnap[8,9] ) .
274 " $filename failed: $!" );
275 return undef;
276 }
277
278 if ( !chown @$statsnap[4,5], $filename ) {
279 bz_seterror( &BZ_IO_ERROR,
280 "chown " . join(':', ( getpwuid($statsnap->[4]) )[0], ( getgrgid($statsnap->[5]) )[0]) .
281 " $filename failed: $!" );
282 return 0;
283 }
284
285 return 1;
286}
287
288sub bzip2 ( @ ) {
289 return _process_files( 'bzip2', 'cfvks123456789', @_ );
290}
291
292sub bunzip2 ( @ ) {
293 return _process_files( 'bunzip2', 'cdzfks123456789', @_ );
294}
295
296sub bzcat ( @ ) {
297 return _process_files( 'bzcat', 'cdzfks123456789', @_ );
298}
299
300sub _process_files ( @ ) {
301 my $command = shift;
302 my $opts = shift;
303
304 local @ARGV = @_;
305
306 my %opts;
307 return undef if !getopt( $opts, \%opts );
308 # c compress or decompress to stdout
309 # d decompress
310 # z compress
311 # f force
312 # v verbose
313 # k keep
314 # s small
315 # 123456789
316
317 $opts{c} = 1 if $command eq 'bzcat';
318 $opts{d} = 1 if $command eq 'bunzip2' || $command eq 'bzcat';
319 $opts{z} = 1 if $command eq 'bzip2';
320
321 my $read_from_stdin;
322 my ( $in, $bzin );
323 my ( $out, $bzout );
324
325 if ( !@ARGV ) {
326 $read_from_stdin = 1;
327 $opts{c} = 1;
328 if ( !open( $in, "<&STDIN" ) ) {
329 die "Error: failed to input from STDIN: '$!'\n";
330 }
331
332 $bzin = bzopen( $in, "r" );
333 }
334
335 if ( $opts{c} ) {
336 if ( !open( $out, ">&STDOUT" ) ) {
337 die "Error: failed to output to STDOUT: '$!'\n";
338 }
339
340 $bzout = bzopen( $out, "w" );
341 }
342
343 if ( !$opts{d} && !$opts{z} ) {
344 die "Error: neither compress nor decompress was indicated.\n";
345 }
346
347 my $doneflag = 0;
348 while ( !$doneflag ) {
349 my $infile;
350 my $outfile;
351 my @statbuf;
352
353 if ( !$read_from_stdin ) {
354 $infile = shift @ARGV;
355 if ( ! -r $infile ) {
356 print STDERR "Error: file $infile is not readable\n";
357 next;
358 }
359
360 @statbuf = stat _;
361 if ( !@statbuf ) {
362 print STDERR "Error: failed to stat $infile: '$!'\n";
363 next;
364 }
365
366 if ( !_check_stat( $infile, \@statbuf, $opts{f} ) ) {
367 print STDERR "Error: file $infile stat check fails: $bzerrno\n";
368 next;
369 }
370 }
371
372 my $outfile_exists;
373 if ( !$opts{c} ) {
374 undef $out;
375 if ( $opts{d} ) {
376 $outfile = $infile . '.bz2';
377 }
378 elsif ( $opts{z} ) {
379 $outfile = $infile =~ /\.bz2$/ ? substr($infile,0,-4) : $infile.'.out';
380 }
381
382 $outfile_exists = -e $outfile;
383 if ( !_writefileopen( $out, $outfile, $opts{f} ) ) {
384 print STDERR "Error: failed to open $outfile for write: '$!'\n";
385 next;
386 }
387 }
388
389 if ( !$read_from_stdin ) {
390 undef $in;
391 if ( !open( $in, $infile ) ) {
392 print STDERR "Error: unable to open $infile: '$!'\n";
393 unlink( $outfile ) if !$outfile_exists;
394 next;
395 }
396 }
397
398 if ( $opts{d} ) {
399 $bzin = bzopen( $in, "r" ) if !$read_from_stdin;
400
401 my $buf;
402 my $notdone = 1;
403 while ( $notdone ) {
404 my $ln = bzread( $in, $buf, 1024 );
405 if ( $ln > 0 ) {
406 syswrite( $out, $buf, $ln );
407 }
408 elsif ( $ln == 0 ) {
409 undef $notdone;
410 }
411 else {
412 }
413 }
414
415 close($out);
416
417 if ( !$read_from_stdin ) {
418 bzclose($in);
419 unlink( $infile ) if !$opts{k};
420 _set_stat_from_snapshot( $outfile, \@statbuf );
421 }
422 }
423 elsif ( $opts{z} ) {
424 $bzout = bzopen( $out, "w" ) if !$opts{c};
425
426 my $buf;
427 my $notdone = 1;
428 while ( $notdone ) {
429 my $ln = sysread( $in, $buf, 1024 );
430 if ( $ln > 0 ) {
431 bzwrite( $bzout, $buf, $ln );
432 }
433 elsif ( $ln == 0 ) {
434 undef $notdone;
435 }
436 else {
437 }
438 }
439
440 close($in);
441
442 if ( !$opts{c} ) {
443 bzclose($bzout);
444 unlink( $infile ) if !$opts{k};
445 _set_stat_from_snapshot( $outfile, \@statbuf );
446 }
447 }
448 }
449}
450
451##############################################################################
452##############################################################################
453## compatibility with Compress::Bzip2 1.03
454
455sub add ( $$ ) {
456 my ( $obj, $buffer ) = @_;
457
458 my @res = $obj->is_write ? $obj->bzdeflate( $buffer ) : $obj->bzinflate( $buffer );
459
460 return $res[0];
461}
462
463sub finish ( $;$ ) {
464 my ( $obj, $buffer ) = @_;
465 my ( @res, $out );
466
467 if ( defined($buffer) ) {
468 @res = $obj->is_write ? $obj->bzdeflate( $buffer ) : $obj->bzinflate( $buffer );
469 return undef if $res[1] != &BZ_OK;
470
471 $out = $res[0];
472 }
473 $out = '' if !defined($out);
474
475 @res = $obj->bzclose;
476 return undef if $res[1] != &BZ_OK;
477
478 return $out.$res[0];
479}
480
481sub input_size ( $ ) {
482 my ( $obj ) = @_;
483 return $obj->total_in;
484}
485
486sub output_size ( $ ) {
487 my ( $obj ) = @_;
488 return $obj->total_out;
489}
490
491sub version ( ) {
492 return bzlibversion();
493}
494
495sub error ( $ ) {
496 return $_[0]->bzerror;
497}
498
499##############################################################################
500##############################################################################
501## THE Compress::Zlib compatibility section
502
503sub _bzerror2gzerror {
504 my ( $bz_error_num ) = @_;
505 my $gz_error_num =
506 $bz_error_num == &BZ_OK ? Z_OK :
507 $bz_error_num == &BZ_RUN_OK ? Z_OK :
508 $bz_error_num == &BZ_FLUSH_OK ? Z_STREAM_END :
509 $bz_error_num == &BZ_FINISH_OK ? Z_STREAM_END :
510 $bz_error_num == &BZ_STREAM_END ? Z_STREAM_END :
511
512 $bz_error_num == &BZ_SEQUENCE_ERROR ? Z_VERSION_ERROR :
513 $bz_error_num == &BZ_PARAM_ERROR ? Z_ERRNO :
514 $bz_error_num == &BZ_MEM_ERROR ? Z_MEM_ERROR :
515 $bz_error_num == &BZ_DATA_ERROR ? Z_DATA_ERROR :
516 $bz_error_num == &BZ_DATA_ERROR_MAGIC ? Z_DATA_ERROR :
517 $bz_error_num == &BZ_IO_ERROR ? Z_ERRNO :
518 $bz_error_num == &BZ_UNEXPECTED_EOF ? Z_STREAM_ERROR :
519 $bz_error_num == &BZ_OUTBUFF_FULL ? Z_BUF_ERROR :
520 $bz_error_num == &BZ_CONFIG_ERROR ? Z_VERSION_ERROR :
521 Z_VERSION_ERROR
522 ;
523
524 return $gz_error_num;
525}
526
527sub gzopen ( $$ ) {
528 goto &bzopen;
529}
530
531sub gzread ( $$;$ ) {
532 goto &bzread;
533}
534
535sub gzreadline ( $$ ) {
536 goto &bzreadline;
537}
538
539sub gzwrite ( $$ ) {
540 goto &bzwrite;
541}
542
543sub gzflush ( $;$ ) {
544 my ( $obj, $flush ) = @_;
545 return Z_OK if $flush == Z_NO_FLUSH;
546 goto &bzflush;
547}
548
549sub gzclose ( $ ) {
550 goto &bzclose;
551}
552
553sub gzeof ( $ ) {
554 goto &bzeof;
555}
556
557sub gzsetparams ( $$$ ) {
558 ## ignore params
559 my ( $obj, $level, $strategy ) = @_;
560 return Z_OK;
561}
562
563sub gzerror ( $ ) {
564 goto &bzerror;
565}
566
567sub deflateInit ( @ ) {
568 ## ignore all options:
569 ## -Level, -Method, -WindowBits, -MemLevel, -Strategy, -Dictionary, -Bufsize
570
571 my @res = bzdeflateInit();
572 return $res[0] if !wantarray;
573
574 return ( $res[0], _bzerror2gzerror( $res[1] ) );
575}
576
577sub deflate ( $$ ) {
578 my ( $obj, $buffer ) = @_;
579
580 my @res = $obj->bzdeflate( $buffer );
581
582 return $res[0] if !wantarray;
583 return ( $res[0], _bzerror2gzerror( $res[1] ) );
584}
585
586sub deflateParams ( $;@ ) {
587 ## ignore all options
588 return Z_OK;
589}
590
591sub flush ( $;$ ) {
592 my ( $obj, $flush_type ) = @_;
593
594 $flush_type = Z_FINISH if !defined($flush_type);
595 return Z_OK if $flush_type == Z_NO_FLUSH;
596
597 my $bz_flush_type;
598 my @res;
599
600 $bz_flush_type =
601 $flush_type == Z_PARTIAL_FLUSH || $flush_type == Z_SYNC_FLUSH ? &BZ_FLUSH :
602 $flush_type == Z_FULL_FLUSH ? &BZ_FINISH :
603 &BZ_FINISH;
604
605 @res = $obj->bzflush( $bz_flush_type );
606
607 return $res[0] if !wantarray;
608 return ( $res[0], _bzerror2gzerror( $res[1] ) );
609}
610
611sub dict_adler ( $ ) {
612 return 1; # ???
613}
614
615sub msg ( $ ) {
616 my ( $obj ) = @_;
617
618 return ''.($obj->bzerror).''; # stringify
619}
620
621sub inflateInit ( @ ) {
622 ## ignore all options:
623 ## -WindowBits, -Dictionary, -Bufsize
624
625 my @res = bzinflateInit();
626 return $res[0] if !wantarray;
627
628 return ( $res[0], _bzerror2gzerror( $res[1] ) );
629}
630
631sub inflate ( $$ ) {
632 my ( $obj, $buffer ) = @_;
633
634 my @res = $obj->bzinflate( $buffer );
635
636 return $res[0] if !wantarray;
637 return ( $res[0], _bzerror2gzerror( $res[1] ) );
638}
639
640sub inflateSync ( $ ) {
641 return Z_VERSION_ERROR; # ?? what
642}
643
644sub memGzip ( $ ) {
645 goto &memBzip;
646}
647
648sub memGunzip ( $ ) {
649 goto &memBunzip;
650}
651
652sub adler32 ( $;$ ) {
653 return 0;
654}
655
656sub crc32 ( $;$ ) {
657 return 0;
658}
659
660# sub compress ( $;$ ) {
661# ## ignore $level
662# my ( $source, $level ) = @_;
663# return memBzip( $source );
664# }
665
666sub uncompress ( $ ) {
667 my ( $source, $level ) = @_;
668 return memBunzip( $source );
669}
670
671# Autoload methods go after =cut, and are processed by the autosplit program.
672
673120µs1;
674
675__END__