| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0/IO/Uncompress/RawInflate.pm |
| Statements | Executed 26 statements in 868µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 3.71ms | 4.08ms | IO::Uncompress::RawInflate::BEGIN@11 |
| 1 | 1 | 1 | 415µs | 593µs | IO::Uncompress::RawInflate::BEGIN@12 |
| 1 | 1 | 1 | 8µs | 9µs | IO::Uncompress::RawInflate::BEGIN@4 |
| 1 | 1 | 1 | 7µs | 107µs | IO::Uncompress::RawInflate::BEGIN@8 |
| 1 | 1 | 1 | 7µs | 61µs | IO::Uncompress::RawInflate::BEGIN@9 |
| 1 | 1 | 1 | 6µs | 8µs | IO::Uncompress::RawInflate::BEGIN@5 |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::_isRaw |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::_isRawx |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::chkTrailer |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::ckMagic |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::ckParams |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::createDeflate |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::getExtraParams |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::inflateSync |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::mkUncomp |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::new |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::rawinflate |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::readHeader |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::scan |
| 0 | 0 | 0 | 0s | 0s | IO::Uncompress::RawInflate::zap |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package IO::Uncompress::RawInflate ; | ||||
| 2 | # for RFC1951 | ||||
| 3 | |||||
| 4 | 2 | 13µs | 2 | 11µs | # spent 9µs (8+1) within IO::Uncompress::RawInflate::BEGIN@4 which was called:
# once (8µs+1µs) by IO::Uncompress::Inflate::BEGIN@11 at line 4 # spent 9µs making 1 call to IO::Uncompress::RawInflate::BEGIN@4
# spent 1µs making 1 call to strict::import |
| 5 | 2 | 14µs | 2 | 11µs | # spent 8µs (6+3) within IO::Uncompress::RawInflate::BEGIN@5 which was called:
# once (6µs+3µs) by IO::Uncompress::Inflate::BEGIN@11 at line 5 # spent 8µs making 1 call to IO::Uncompress::RawInflate::BEGIN@5
# spent 3µs making 1 call to warnings::import |
| 6 | #use bytes; | ||||
| 7 | |||||
| 8 | 3 | 25µs | 3 | 208µs | # spent 107µs (7+100) within IO::Uncompress::RawInflate::BEGIN@8 which was called:
# once (7µs+100µs) by IO::Uncompress::Inflate::BEGIN@11 at line 8 # spent 107µs making 1 call to IO::Uncompress::RawInflate::BEGIN@8
# spent 96µs making 1 call to Exporter::import
# spent 5µs making 1 call to UNIVERSAL::VERSION |
| 9 | 3 | 25µs | 3 | 115µs | # spent 61µs (7+54) within IO::Uncompress::RawInflate::BEGIN@9 which was called:
# once (7µs+54µs) by IO::Uncompress::Inflate::BEGIN@11 at line 9 # spent 61µs making 1 call to IO::Uncompress::RawInflate::BEGIN@9
# spent 50µs making 1 call to Exporter::import
# spent 4µs making 1 call to UNIVERSAL::VERSION |
| 10 | |||||
| 11 | 3 | 96µs | 3 | 4.11ms | # spent 4.08ms (3.71+371µs) within IO::Uncompress::RawInflate::BEGIN@11 which was called:
# once (3.71ms+371µs) by IO::Uncompress::Inflate::BEGIN@11 at line 11 # spent 4.08ms making 1 call to IO::Uncompress::RawInflate::BEGIN@11
# spent 19µs making 1 call to Exporter::import
# spent 9µs making 1 call to UNIVERSAL::VERSION |
| 12 | 3 | 680µs | 2 | 598µs | # spent 593µs (415+177) within IO::Uncompress::RawInflate::BEGIN@12 which was called:
# once (415µs+177µs) by IO::Uncompress::Inflate::BEGIN@11 at line 12 # spent 593µs making 1 call to IO::Uncompress::RawInflate::BEGIN@12
# spent 5µs making 1 call to UNIVERSAL::VERSION |
| 13 | |||||
| 14 | 1 | 400ns | require Exporter ; | ||
| 15 | our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $RawInflateError); | ||||
| 16 | |||||
| 17 | 1 | 300ns | $VERSION = '2.068'; | ||
| 18 | 1 | 100ns | $RawInflateError = ''; | ||
| 19 | |||||
| 20 | 1 | 5µs | @ISA = qw( Exporter IO::Uncompress::Base ); | ||
| 21 | 1 | 400ns | @EXPORT_OK = qw( $RawInflateError rawinflate ) ; | ||
| 22 | 1 | 300ns | %DEFLATE_CONSTANTS = (); | ||
| 23 | 1 | 1µs | %EXPORT_TAGS = %IO::Uncompress::Base::EXPORT_TAGS ; | ||
| 24 | 1 | 600ns | push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; | ||
| 25 | 1 | 2µs | 1 | 14µs | Exporter::export_ok_tags('all'); # spent 14µs making 1 call to Exporter::export_ok_tags |
| 26 | |||||
| 27 | #{ | ||||
| 28 | # # Execute at runtime | ||||
| 29 | # my %bad; | ||||
| 30 | # for my $module (qw(Compress::Raw::Zlib IO::Compress::Base::Common IO::Uncompress::Base IO::Uncompress::Adapter::Inflate)) | ||||
| 31 | # { | ||||
| 32 | # my $ver = ${ $module . "::VERSION"} ; | ||||
| 33 | # | ||||
| 34 | # $bad{$module} = $ver | ||||
| 35 | # if $ver ne $VERSION; | ||||
| 36 | # } | ||||
| 37 | # | ||||
| 38 | # if (keys %bad) | ||||
| 39 | # { | ||||
| 40 | # my $string = join "\n", map { "$_ $bad{$_}" } keys %bad; | ||||
| 41 | # die caller(0)[0] . "needs version $VERSION mismatch\n$string\n"; | ||||
| 42 | # } | ||||
| 43 | #} | ||||
| 44 | |||||
| 45 | sub new | ||||
| 46 | { | ||||
| 47 | my $class = shift ; | ||||
| 48 | my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$RawInflateError); | ||||
| 49 | $obj->_create(undef, 0, @_); | ||||
| 50 | } | ||||
| 51 | |||||
| 52 | sub rawinflate | ||||
| 53 | { | ||||
| 54 | my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$RawInflateError); | ||||
| 55 | return $obj->_inf(@_); | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | sub getExtraParams | ||||
| 59 | { | ||||
| 60 | return (); | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | sub ckParams | ||||
| 64 | { | ||||
| 65 | my $self = shift ; | ||||
| 66 | my $got = shift ; | ||||
| 67 | |||||
| 68 | return 1; | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | sub mkUncomp | ||||
| 72 | { | ||||
| 73 | my $self = shift ; | ||||
| 74 | my $got = shift ; | ||||
| 75 | |||||
| 76 | my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Inflate::mkUncompObject( | ||||
| 77 | $got->getValue('crc32'), | ||||
| 78 | $got->getValue('adler32'), | ||||
| 79 | $got->getValue('scan'), | ||||
| 80 | ); | ||||
| 81 | |||||
| 82 | return $self->saveErrorString(undef, $errstr, $errno) | ||||
| 83 | if ! defined $obj; | ||||
| 84 | |||||
| 85 | *$self->{Uncomp} = $obj; | ||||
| 86 | |||||
| 87 | my $magic = $self->ckMagic() | ||||
| 88 | or return 0; | ||||
| 89 | |||||
| 90 | *$self->{Info} = $self->readHeader($magic) | ||||
| 91 | or return undef ; | ||||
| 92 | |||||
| 93 | return 1; | ||||
| 94 | |||||
| 95 | } | ||||
| 96 | |||||
| 97 | |||||
| 98 | sub ckMagic | ||||
| 99 | { | ||||
| 100 | my $self = shift; | ||||
| 101 | |||||
| 102 | return $self->_isRaw() ; | ||||
| 103 | } | ||||
| 104 | |||||
| 105 | sub readHeader | ||||
| 106 | { | ||||
| 107 | my $self = shift; | ||||
| 108 | my $magic = shift ; | ||||
| 109 | |||||
| 110 | return { | ||||
| 111 | 'Type' => 'rfc1951', | ||||
| 112 | 'FingerprintLength' => 0, | ||||
| 113 | 'HeaderLength' => 0, | ||||
| 114 | 'TrailerLength' => 0, | ||||
| 115 | 'Header' => '' | ||||
| 116 | }; | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | sub chkTrailer | ||||
| 120 | { | ||||
| 121 | return STATUS_OK ; | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | sub _isRaw | ||||
| 125 | { | ||||
| 126 | my $self = shift ; | ||||
| 127 | |||||
| 128 | my $got = $self->_isRawx(@_); | ||||
| 129 | |||||
| 130 | if ($got) { | ||||
| 131 | *$self->{Pending} = *$self->{HeaderPending} ; | ||||
| 132 | } | ||||
| 133 | else { | ||||
| 134 | $self->pushBack(*$self->{HeaderPending}); | ||||
| 135 | *$self->{Uncomp}->reset(); | ||||
| 136 | } | ||||
| 137 | *$self->{HeaderPending} = ''; | ||||
| 138 | |||||
| 139 | return $got ; | ||||
| 140 | } | ||||
| 141 | |||||
| 142 | sub _isRawx | ||||
| 143 | { | ||||
| 144 | my $self = shift ; | ||||
| 145 | my $magic = shift ; | ||||
| 146 | |||||
| 147 | $magic = '' unless defined $magic ; | ||||
| 148 | |||||
| 149 | my $buffer = ''; | ||||
| 150 | |||||
| 151 | $self->smartRead(\$buffer, *$self->{BlockSize}) >= 0 | ||||
| 152 | or return $self->saveErrorString(undef, "No data to read"); | ||||
| 153 | |||||
| 154 | my $temp_buf = $magic . $buffer ; | ||||
| 155 | *$self->{HeaderPending} = $temp_buf ; | ||||
| 156 | $buffer = ''; | ||||
| 157 | my $status = *$self->{Uncomp}->uncompr(\$temp_buf, \$buffer, $self->smartEof()) ; | ||||
| 158 | |||||
| 159 | return $self->saveErrorString(undef, *$self->{Uncomp}{Error}, STATUS_ERROR) | ||||
| 160 | if $status == STATUS_ERROR; | ||||
| 161 | |||||
| 162 | $self->pushBack($temp_buf) ; | ||||
| 163 | |||||
| 164 | return $self->saveErrorString(undef, "unexpected end of file", STATUS_ERROR) | ||||
| 165 | if $self->smartEof() && $status != STATUS_ENDSTREAM; | ||||
| 166 | |||||
| 167 | #my $buf_len = *$self->{Uncomp}->uncompressedBytes(); | ||||
| 168 | my $buf_len = length $buffer; | ||||
| 169 | |||||
| 170 | if ($status == STATUS_ENDSTREAM) { | ||||
| 171 | if (*$self->{MultiStream} | ||||
| 172 | && (length $temp_buf || ! $self->smartEof())){ | ||||
| 173 | *$self->{NewStream} = 1 ; | ||||
| 174 | *$self->{EndStream} = 0 ; | ||||
| 175 | } | ||||
| 176 | else { | ||||
| 177 | *$self->{EndStream} = 1 ; | ||||
| 178 | } | ||||
| 179 | } | ||||
| 180 | *$self->{HeaderPending} = $buffer ; | ||||
| 181 | *$self->{InflatedBytesRead} = $buf_len ; | ||||
| 182 | *$self->{TotalInflatedBytesRead} += $buf_len ; | ||||
| 183 | *$self->{Type} = 'rfc1951'; | ||||
| 184 | |||||
| 185 | $self->saveStatus(STATUS_OK); | ||||
| 186 | |||||
| 187 | return { | ||||
| 188 | 'Type' => 'rfc1951', | ||||
| 189 | 'HeaderLength' => 0, | ||||
| 190 | 'TrailerLength' => 0, | ||||
| 191 | 'Header' => '' | ||||
| 192 | }; | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | |||||
| 196 | sub inflateSync | ||||
| 197 | { | ||||
| 198 | my $self = shift ; | ||||
| 199 | |||||
| 200 | # inflateSync is a no-op in Plain mode | ||||
| 201 | return 1 | ||||
| 202 | if *$self->{Plain} ; | ||||
| 203 | |||||
| 204 | return 0 if *$self->{Closed} ; | ||||
| 205 | #return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ; | ||||
| 206 | return 0 if ! length *$self->{Pending} && *$self->{EndStream} ; | ||||
| 207 | |||||
| 208 | # Disable CRC check | ||||
| 209 | *$self->{Strict} = 0 ; | ||||
| 210 | |||||
| 211 | my $status ; | ||||
| 212 | while (1) | ||||
| 213 | { | ||||
| 214 | my $temp_buf ; | ||||
| 215 | |||||
| 216 | if (length *$self->{Pending} ) | ||||
| 217 | { | ||||
| 218 | $temp_buf = *$self->{Pending} ; | ||||
| 219 | *$self->{Pending} = ''; | ||||
| 220 | } | ||||
| 221 | else | ||||
| 222 | { | ||||
| 223 | $status = $self->smartRead(\$temp_buf, *$self->{BlockSize}) ; | ||||
| 224 | return $self->saveErrorString(0, "Error Reading Data") | ||||
| 225 | if $status < 0 ; | ||||
| 226 | |||||
| 227 | if ($status == 0 ) { | ||||
| 228 | *$self->{EndStream} = 1 ; | ||||
| 229 | return $self->saveErrorString(0, "unexpected end of file", STATUS_ERROR); | ||||
| 230 | } | ||||
| 231 | } | ||||
| 232 | |||||
| 233 | $status = *$self->{Uncomp}->sync($temp_buf) ; | ||||
| 234 | |||||
| 235 | if ($status == STATUS_OK) | ||||
| 236 | { | ||||
| 237 | *$self->{Pending} .= $temp_buf ; | ||||
| 238 | return 1 ; | ||||
| 239 | } | ||||
| 240 | |||||
| 241 | last unless $status == STATUS_ERROR ; | ||||
| 242 | } | ||||
| 243 | |||||
| 244 | return 0; | ||||
| 245 | } | ||||
| 246 | |||||
| 247 | #sub performScan | ||||
| 248 | #{ | ||||
| 249 | # my $self = shift ; | ||||
| 250 | # | ||||
| 251 | # my $status ; | ||||
| 252 | # my $end_offset = 0; | ||||
| 253 | # | ||||
| 254 | # $status = $self->scan() | ||||
| 255 | # #or return $self->saveErrorString(undef, "Error Scanning: $$error_ref", $self->errorNo) ; | ||||
| 256 | # or return $self->saveErrorString(G_ERR, "Error Scanning: $status") | ||||
| 257 | # | ||||
| 258 | # $status = $self->zap($end_offset) | ||||
| 259 | # or return $self->saveErrorString(G_ERR, "Error Zapping: $status"); | ||||
| 260 | # #or return $self->saveErrorString(undef, "Error Zapping: $$error_ref", $self->errorNo) ; | ||||
| 261 | # | ||||
| 262 | # #(*$obj->{Deflate}, $status) = $inf->createDeflate(); | ||||
| 263 | # | ||||
| 264 | ## *$obj->{Header} = *$inf->{Info}{Header}; | ||||
| 265 | ## *$obj->{UnCompSize_32bit} = | ||||
| 266 | ## *$obj->{BytesWritten} = *$inf->{UnCompSize_32bit} ; | ||||
| 267 | ## *$obj->{CompSize_32bit} = *$inf->{CompSize_32bit} ; | ||||
| 268 | # | ||||
| 269 | # | ||||
| 270 | ## if ( $outType eq 'buffer') | ||||
| 271 | ## { substr( ${ *$self->{Buffer} }, $end_offset) = '' } | ||||
| 272 | ## elsif ($outType eq 'handle' || $outType eq 'filename') { | ||||
| 273 | ## *$self->{FH} = *$inf->{FH} ; | ||||
| 274 | ## delete *$inf->{FH}; | ||||
| 275 | ## *$obj->{FH}->flush() ; | ||||
| 276 | ## *$obj->{Handle} = 1 if $outType eq 'handle'; | ||||
| 277 | ## | ||||
| 278 | ## #seek(*$obj->{FH}, $end_offset, SEEK_SET) | ||||
| 279 | ## *$obj->{FH}->seek($end_offset, SEEK_SET) | ||||
| 280 | ## or return $obj->saveErrorString(undef, $!, $!) ; | ||||
| 281 | ## } | ||||
| 282 | # | ||||
| 283 | #} | ||||
| 284 | |||||
| 285 | sub scan | ||||
| 286 | { | ||||
| 287 | my $self = shift ; | ||||
| 288 | |||||
| 289 | return 1 if *$self->{Closed} ; | ||||
| 290 | return 1 if !length *$self->{Pending} && *$self->{EndStream} ; | ||||
| 291 | |||||
| 292 | my $buffer = '' ; | ||||
| 293 | my $len = 0; | ||||
| 294 | |||||
| 295 | $len = $self->_raw_read(\$buffer, 1) | ||||
| 296 | while ! *$self->{EndStream} && $len >= 0 ; | ||||
| 297 | |||||
| 298 | #return $len if $len < 0 ? $len : 0 ; | ||||
| 299 | return $len < 0 ? 0 : 1 ; | ||||
| 300 | } | ||||
| 301 | |||||
| 302 | sub zap | ||||
| 303 | { | ||||
| 304 | my $self = shift ; | ||||
| 305 | |||||
| 306 | my $headerLength = *$self->{Info}{HeaderLength}; | ||||
| 307 | my $block_offset = $headerLength + *$self->{Uncomp}->getLastBlockOffset(); | ||||
| 308 | $_[0] = $headerLength + *$self->{Uncomp}->getEndOffset(); | ||||
| 309 | #printf "# End $_[0], headerlen $headerLength \n";; | ||||
| 310 | #printf "# block_offset $block_offset %x\n", $block_offset; | ||||
| 311 | my $byte ; | ||||
| 312 | ( $self->smartSeek($block_offset) && | ||||
| 313 | $self->smartRead(\$byte, 1) ) | ||||
| 314 | or return $self->saveErrorString(0, $!, $!); | ||||
| 315 | |||||
| 316 | #printf "#byte is %x\n", unpack('C*',$byte); | ||||
| 317 | *$self->{Uncomp}->resetLastBlockByte($byte); | ||||
| 318 | #printf "#to byte is %x\n", unpack('C*',$byte); | ||||
| 319 | |||||
| 320 | ( $self->smartSeek($block_offset) && | ||||
| 321 | $self->smartWrite($byte) ) | ||||
| 322 | or return $self->saveErrorString(0, $!, $!); | ||||
| 323 | |||||
| 324 | #$self->smartSeek($end_offset, 1); | ||||
| 325 | |||||
| 326 | return 1 ; | ||||
| 327 | } | ||||
| 328 | |||||
| 329 | sub createDeflate | ||||
| 330 | { | ||||
| 331 | my $self = shift ; | ||||
| 332 | my ($def, $status) = *$self->{Uncomp}->createDeflateStream( | ||||
| 333 | -AppendOutput => 1, | ||||
| 334 | -WindowBits => - MAX_WBITS, | ||||
| 335 | -CRC32 => *$self->{Params}->getValue('crc32'), | ||||
| 336 | -ADLER32 => *$self->{Params}->getValue('adler32'), | ||||
| 337 | ); | ||||
| 338 | |||||
| 339 | return wantarray ? ($status, $def) : $def ; | ||||
| 340 | } | ||||
| 341 | |||||
| 342 | |||||
| 343 | 1 | 5µs | 1; | ||
| 344 | |||||
| 345 | __END__ |