| 1 | package Archive::Lha::Header::Level1; | ||||||||||
| 2 | |||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 17 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 17 | ▶ | use Archive::Lha::Constants; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 17 | ▶ | use Archive::Lha::Header::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 17 | ▶ | use Archive::Lha::Header::Utils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 239 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||
| 11 | 239 | my ($class, $stream) = @_; | |||||||||
| 12 | |||||||||||
| 13 | 239 | my $start = $stream->tell; | |||||||||
| 14 | 239 | my $size = ord($stream->read(1)) + 2; | |||||||||
| 15 | |||||||||||
| 16 | 239 | ▶ | croak "Header is broken: size is too small: $size" if $size < 27; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | 239 | $stream->seek($start); | |||||||||
| 19 | 239 | my $buf = $stream->read($size); | |||||||||
| 20 | |||||||||||
| 21 | 239 | my $checksum = ord(substr($buf, 1, 1)); | |||||||||
| 22 | 239 | my $checksum1 = _checksum($buf, 2); | |||||||||
| 23 | 239 | ▶ | croak "Header is broken: checksum $checksum/$checksum1" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | unless $checksum == $checksum1; | ||||||||||
| 25 | |||||||||||
| 26 | 239 | my %header; | |||||||||
| 27 | 239 | $header{header_top} = $start; | |||||||||
| 28 | 239 | $header{header_size} = $size; | |||||||||
| 29 | 239 | $header{header_checksum} = $checksum; | |||||||||
| 30 | 239 | $header{method} = substr($buf, 3, 3); | |||||||||
| 31 | 239 | $header{skip_size} = unpack 'V', substr($buf, 7, 4); | |||||||||
| 32 | 239 | $header{original_size} = unpack 'V', substr($buf, 11, 4); | |||||||||
| 33 | 239 | $header{timestamp} = unpack 'V', substr($buf, 15, 4); | |||||||||
| 34 | |||||||||||
| 35 | 239 | my $filename_length = ord(substr($buf, 21, 1)); | |||||||||
| 36 | 239 | $header{filename} = substr($buf, 22, $filename_length); | |||||||||
| 37 | 239 | $header{filename} =~ s/\0.*//s; | |||||||||
| 38 | 239 | $header{crc16} = unpack 'v', substr($buf, 22 + $filename_length, 2); | |||||||||
| 39 | 239 | $header{os} = _os_id( substr($buf, 24 + $filename_length, 1) ); | |||||||||
| 40 | |||||||||||
| 41 | 239 | my $ext_from = 25 + $filename_length; | |||||||||
| 42 | 239 | my $ext_to = $size - 3; | |||||||||
| 43 | 239 | ▶ | if ($ext_from < $ext_to) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | my (undef, $ext) = _extended_header_buf($buf, $ext_from, $ext_to - $ext_from + 2); | |||||||||
| 45 | 0 | ▶ | %header = (%header, %{ $ext }) if %{ $ext }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 239 | my $extended_size_total = 0; | |||||||||
| 49 | 239 | my $extended_size = unpack 'v', substr($buf, -2, 2); | |||||||||
| 50 | 239 | ▶ | while ($extended_size) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 466 | my $chunk = $stream->read($extended_size); | |||||||||
| 52 | 466 | $extended_size_total += $extended_size; | |||||||||
| 53 | 466 | my ($next, $hash) = _extended_header_buf($chunk, 0, $extended_size); | |||||||||
| 54 | 466 | ▶ | %header = (%header, %{ $hash }) if %{ $hash }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 466 | $extended_size = $next; | |||||||||
| 56 | } | ||||||||||
| 57 | 239 | $header{encoded_size} = $header{skip_size} - $extended_size_total; | |||||||||
| 58 | |||||||||||
| 59 | 239 | $header{data_top} = $start + $size + $extended_size_total; | |||||||||
| 60 | 239 | $header{next_header} = $header{data_top} + $header{encoded_size}; | |||||||||
| 61 | |||||||||||
| 62 | 239 | bless \%header, $class; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 17 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||