| 1 | package Archive::Lha::Header::Level2; | ||||||||||
| 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::Header::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 17 | ▶ | use Archive::Lha::Header::Utils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 57 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 10 | 57 | my ($class, $stream) = @_; | |||||||||
| 11 | |||||||||||
| 12 | 57 | my $start = $stream->tell; | |||||||||
| 13 | 57 | my $size = unpack 'v', $stream->read(2); | |||||||||
| 14 | |||||||||||
| 15 | 57 | ▶ | croak "Header is broken: size is null" unless $size; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 57 | ▶ | croak "Header is too large: $size" if $size > 4096; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | 57 | $stream->seek($start); | |||||||||
| 19 | 57 | my $buf = $stream->read($size); | |||||||||
| 20 | |||||||||||
| 21 | 57 | my %header; | |||||||||
| 22 | 57 | $header{header_top} = $start; | |||||||||
| 23 | 57 | $header{header_size} = $size; | |||||||||
| 24 | 57 | $header{method} = substr($buf, 3, 3); | |||||||||
| 25 | 57 | $header{encoded_size} = unpack 'V', substr($buf, 7, 4); | |||||||||
| 26 | 57 | $header{original_size} = unpack 'V', substr($buf, 11, 4); | |||||||||
| 27 | 57 | $header{timestamp} = unpack 'V', substr($buf, 15, 4); | |||||||||
| 28 | 57 | $header{timestamp_is_unix} = 1; | |||||||||
| 29 | 57 | $header{crc16} = unpack 'v', substr($buf, 21, 2); | |||||||||
| 30 | 57 | $header{os} = _os_id( substr($buf, 23, 1) ); | |||||||||
| 31 | 57 | $header{data_top} = $start + $size; | |||||||||
| 32 | 57 | $header{next_header} = $header{data_top} + $header{encoded_size}; | |||||||||
| 33 | |||||||||||
| 34 | 57 | my $from = 26; | |||||||||
| 35 | 57 | my $extended_size = unpack 'v', substr($buf, 24, 2); | |||||||||
| 36 | 57 | ▶ | while ($extended_size) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 284 | my ($next, $hash) = _extended_header_buf($buf, $from, $extended_size); | |||||||||
| 38 | 284 | ▶ | %header = (%header, %{ $hash }) if %{ $hash }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 284 | $from += $extended_size; | |||||||||
| 40 | 284 | $extended_size = $next; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 57 | bless \%header, $class; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 17 | 1; | |||||||||
| 47 | |||||||||||
| 48 | __END__ | ||||||||||