Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Compress/Bzip2.pm |
Statements | Executed 61 statements in 4.09ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.11ms | 1.15ms | BEGIN@20 | Compress::Bzip2::
1 | 1 | 1 | 37µs | 37µs | BEGIN@14 | Compress::Bzip2::
1 | 1 | 1 | 13µs | 131µs | BEGIN@146 | Compress::Bzip2::
1 | 1 | 1 | 11µs | 63µs | BEGIN@141 | Compress::Bzip2::
1 | 1 | 1 | 11µs | 692µs | BEGIN@21 | Compress::Bzip2::
1 | 1 | 1 | 11µs | 109µs | BEGIN@24 | Compress::Bzip2::
1 | 1 | 1 | 11µs | 66µs | BEGIN@19 | Compress::Bzip2::
1 | 1 | 1 | 9µs | 94µs | BEGIN@143 | Compress::Bzip2::
1 | 1 | 1 | 9µs | 11µs | BEGIN@16 | Compress::Bzip2::
1 | 1 | 1 | 9µs | 25µs | BEGIN@175 | Compress::Bzip2::
1 | 1 | 1 | 8µs | 81µs | BEGIN@153 | Compress::Bzip2::
1 | 1 | 1 | 8µs | 63µs | BEGIN@150 | Compress::Bzip2::
1 | 1 | 1 | 7µs | 54µs | BEGIN@156 | Compress::Bzip2::
1 | 1 | 1 | 7µs | 14µs | BEGIN@17 | Compress::Bzip2::
1 | 1 | 1 | 6µs | 29µs | BEGIN@158 | Compress::Bzip2::
1 | 1 | 1 | 6µs | 28µs | BEGIN@160 | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | AUTOLOAD | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | __ANON__[:181] | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | _bzerror2gzerror | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | _check_stat | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | _process_files | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | _set_stat_from_snapshot | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | _stat_snapshot | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | _writefileopen | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | add | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | adler32 | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | bunzip2 | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | bzcat | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | bzip2 | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | crc32 | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | deflate | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | deflateInit | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | deflateParams | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | dict_adler | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | error | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | finish | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | flush | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzclose | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzeof | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzerror | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzflush | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzopen | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzread | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzreadline | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzsetparams | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | gzwrite | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | inflate | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | inflateInit | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | inflateSync | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | input_size | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | memGunzip | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | memGzip | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | msg | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | output_size | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | uncompress | Compress::Bzip2::
0 | 0 | 0 | 0s | 0s | version | Compress::Bzip2::
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 | |||||
12 | package Compress::Bzip2; | ||||
13 | |||||
14 | 3 | 46µs | 1 | 37µ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 # spent 37µs making 1 call to Compress::Bzip2::BEGIN@14 |
15 | |||||
16 | 3 | 16µs | 2 | 13µ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 # spent 11µs making 1 call to Compress::Bzip2::BEGIN@16
# spent 2µs making 1 call to strict::import |
17 | 3 | 16µs | 2 | 21µ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 # spent 14µs making 1 call to Compress::Bzip2::BEGIN@17
# spent 7µs making 1 call to warnings::import |
18 | |||||
19 | 3 | 22µs | 2 | 121µ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 # spent 66µs making 1 call to Compress::Bzip2::BEGIN@19
# spent 55µs making 1 call to Exporter::import |
20 | 3 | 1.10ms | 2 | 1.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 # spent 1.15ms making 1 call to Compress::Bzip2::BEGIN@20
# spent 32µs making 1 call to Exporter::import |
21 | 3 | 27µs | 2 | 1.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 # spent 692µs making 1 call to Compress::Bzip2::BEGIN@21
# spent 680µs making 1 call to Exporter::import |
22 | |||||
23 | 1 | 1µs | require Exporter; | ||
24 | 3 | 193µs | 2 | 207µ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 # spent 109µs making 1 call to Compress::Bzip2::BEGIN@24
# spent 98µs making 1 call to AutoLoader::import |
25 | |||||
26 | 1 | 10µs | our @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. | ||||
35 | 1 | 12µs | our %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 | |||||
123 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'utilities'} }, | ||||
124 | @{ $EXPORT_TAGS{'constants'} }, | ||||
125 | @{ $EXPORT_TAGS{'bzip1'} }, | ||||
126 | 1 | 20µs | @{ $EXPORT_TAGS{'gzip'} }, | ||
127 | ); | ||||
128 | |||||
129 | 1 | 11µs | $EXPORT_TAGS{'all'} = [ @EXPORT_OK ]; | ||
130 | |||||
131 | 1 | 14µs | our @EXPORT = ( @{ $EXPORT_TAGS{'utilities'} }, @{ $EXPORT_TAGS{'constants'} } ); | ||
132 | |||||
133 | 1 | 400ns | our $VERSION = "2.09"; | ||
134 | |||||
135 | 1 | 200ns | our $bzerrno = ""; | ||
136 | 1 | 100ns | our $gzerrno; | ||
137 | 1 | 900ns | *gzerrno = \$bzerrno; | ||
138 | |||||
139 | # Zlib compatibility | ||||
140 | ## | ||||
141 | 3 | 32µs | 2 | 114µ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 # spent 63µs making 1 call to Compress::Bzip2::BEGIN@141
# spent 51µs making 1 call to constant::import |
142 | # allowed flush values | ||||
143 | 1 | 8µs | 1 | 84µ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 # spent 84µs making 1 call to constant::import |
144 | 2 | 29µs | 1 | 94µ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 | ||||
146 | 1 | 12µs | 1 | 118µ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 # spent 118µs making 1 call to constant::import |
147 | Z_STREAM_ERROR => -2, Z_DATA_ERROR => -3, Z_MEM_ERROR => -4, | ||||
148 | 2 | 22µs | 1 | 131µs | Z_BUF_ERROR => -5, Z_VERSION_ERROR => -6 }; # spent 131µs making 1 call to Compress::Bzip2::BEGIN@146 |
149 | # compression levels | ||||
150 | 1 | 6µs | 1 | 54µ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 # spent 54µs making 1 call to constant::import |
151 | 2 | 19µs | 1 | 63µ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 | ||||
153 | 1 | 6µs | 1 | 72µ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 # spent 72µs making 1 call to constant::import |
154 | 2 | 18µs | 1 | 81µs | Z_DEFAULT_STRATEGY => 0 }; # spent 81µs making 1 call to Compress::Bzip2::BEGIN@153 |
155 | # possible values of data_type (inflate) | ||||
156 | 3 | 21µs | 2 | 100µ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 # 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 | ||||
158 | 3 | 18µs | 2 | 51µ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 # spent 29µs making 1 call to Compress::Bzip2::BEGIN@158
# spent 23µs making 1 call to constant::import |
159 | # for initialization | ||||
160 | 3 | 82µs | 2 | 51µ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 # 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 | |||||
164 | sub 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 | { | ||||
175 | 3 | 1.98ms | 2 | 41µ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 # 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 | |||||
187 | 1 | 800ns | require XSLoader; | ||
188 | 1 | 330µs | 1 | 320µs | XSLoader::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 | |||||
195 | sub _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 | |||||
207 | sub _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 | |||||
220 | sub _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 | |||||
263 | sub _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 | |||||
288 | sub bzip2 ( @ ) { | ||||
289 | return _process_files( 'bzip2', 'cfvks123456789', @_ ); | ||||
290 | } | ||||
291 | |||||
292 | sub bunzip2 ( @ ) { | ||||
293 | return _process_files( 'bunzip2', 'cdzfks123456789', @_ ); | ||||
294 | } | ||||
295 | |||||
296 | sub bzcat ( @ ) { | ||||
297 | return _process_files( 'bzcat', 'cdzfks123456789', @_ ); | ||||
298 | } | ||||
299 | |||||
300 | sub _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 | |||||
455 | sub 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 | |||||
463 | sub 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 | |||||
481 | sub input_size ( $ ) { | ||||
482 | my ( $obj ) = @_; | ||||
483 | return $obj->total_in; | ||||
484 | } | ||||
485 | |||||
486 | sub output_size ( $ ) { | ||||
487 | my ( $obj ) = @_; | ||||
488 | return $obj->total_out; | ||||
489 | } | ||||
490 | |||||
491 | sub version ( ) { | ||||
492 | return bzlibversion(); | ||||
493 | } | ||||
494 | |||||
495 | sub error ( $ ) { | ||||
496 | return $_[0]->bzerror; | ||||
497 | } | ||||
498 | |||||
499 | ############################################################################## | ||||
500 | ############################################################################## | ||||
501 | ## THE Compress::Zlib compatibility section | ||||
502 | |||||
503 | sub _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 | |||||
527 | sub gzopen ( $$ ) { | ||||
528 | goto &bzopen; | ||||
529 | } | ||||
530 | |||||
531 | sub gzread ( $$;$ ) { | ||||
532 | goto &bzread; | ||||
533 | } | ||||
534 | |||||
535 | sub gzreadline ( $$ ) { | ||||
536 | goto &bzreadline; | ||||
537 | } | ||||
538 | |||||
539 | sub gzwrite ( $$ ) { | ||||
540 | goto &bzwrite; | ||||
541 | } | ||||
542 | |||||
543 | sub gzflush ( $;$ ) { | ||||
544 | my ( $obj, $flush ) = @_; | ||||
545 | return Z_OK if $flush == Z_NO_FLUSH; | ||||
546 | goto &bzflush; | ||||
547 | } | ||||
548 | |||||
549 | sub gzclose ( $ ) { | ||||
550 | goto &bzclose; | ||||
551 | } | ||||
552 | |||||
553 | sub gzeof ( $ ) { | ||||
554 | goto &bzeof; | ||||
555 | } | ||||
556 | |||||
557 | sub gzsetparams ( $$$ ) { | ||||
558 | ## ignore params | ||||
559 | my ( $obj, $level, $strategy ) = @_; | ||||
560 | return Z_OK; | ||||
561 | } | ||||
562 | |||||
563 | sub gzerror ( $ ) { | ||||
564 | goto &bzerror; | ||||
565 | } | ||||
566 | |||||
567 | sub 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 | |||||
577 | sub 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 | |||||
586 | sub deflateParams ( $;@ ) { | ||||
587 | ## ignore all options | ||||
588 | return Z_OK; | ||||
589 | } | ||||
590 | |||||
591 | sub 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 | |||||
611 | sub dict_adler ( $ ) { | ||||
612 | return 1; # ??? | ||||
613 | } | ||||
614 | |||||
615 | sub msg ( $ ) { | ||||
616 | my ( $obj ) = @_; | ||||
617 | |||||
618 | return ''.($obj->bzerror).''; # stringify | ||||
619 | } | ||||
620 | |||||
621 | sub 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 | |||||
631 | sub 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 | |||||
640 | sub inflateSync ( $ ) { | ||||
641 | return Z_VERSION_ERROR; # ?? what | ||||
642 | } | ||||
643 | |||||
644 | sub memGzip ( $ ) { | ||||
645 | goto &memBzip; | ||||
646 | } | ||||
647 | |||||
648 | sub memGunzip ( $ ) { | ||||
649 | goto &memBunzip; | ||||
650 | } | ||||
651 | |||||
652 | sub adler32 ( $;$ ) { | ||||
653 | return 0; | ||||
654 | } | ||||
655 | |||||
656 | sub crc32 ( $;$ ) { | ||||
657 | return 0; | ||||
658 | } | ||||
659 | |||||
660 | # sub compress ( $;$ ) { | ||||
661 | # ## ignore $level | ||||
662 | # my ( $source, $level ) = @_; | ||||
663 | # return memBzip( $source ); | ||||
664 | # } | ||||
665 | |||||
666 | sub 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 | |||||
673 | 1 | 20µs | 1; | ||
674 | |||||
675 | __END__ |