File Coverage

lib/Archive/Lha/Decode/LH0.pm
Criterion Covered Total %
statement 34 34 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 45 46 97.8


line stmt bran cond sub pod time code
1             package Archive::Lha::Decode::LH0;
2            
3 2     2   1232 use strict;
  2         5  
  2         82  
4 2     2   11 use warnings;
  2         4  
  2         126  
5 2     2   12 use Carp;
  2         4  
  2         191  
6 2     2   589 use bytes;
  2         581  
  2         18  
7 2     2   534 use Archive::Lha::Constants;
  2         6  
  2         17  
8 2     2   956 use Archive::Lha::CRC;
  2         6  
  2         547  
9            
10             sub new {
11 8     8 1 49 my ($class, %options) = @_;
12            
13 8         19 my $header = $options{header};
14            
15             my $self = bless {
16             read => $options{read},
17             write => $options{write},
18             size => $header->{encoded_size},
19             crc16 => $header->{crc16},
20 8         41 }, $class;
21            
22 8         59 $self;
23             }
24            
25             sub decode {
26 8     8 1 38 my $self = shift;
27            
28 8         17 my $crc = 0;
29 8         11 my $total = 0;
30 8         19 my $size = $self->{size};
31 8         23 while ( $total < $size ) {
32 8         17 my $left = $size - $total;
33 8 50       18 my $length = ( $left > 4096 ) ? 4096 : $left;
34 8         25 my $str = $self->{read}->( $length );
35 8         63 $self->{write}->( $str );
36 8         125 $crc = Archive::Lha::CRC::update( $crc, $str, length($str) );
37 8         29 $total += $length;
38             }
39 8         18 return $crc;
40             }
41            
42             1;
43            
44             __END__