Archive::Lha::Decode::LH0 - Archive::Lha::Decode::LH0 documentation


Archive-Lha documentation Contained in the Archive-Lha distribution.

Index


Code Index:

NAME

Top

Archive::Lha::Decode::LH0

DESCRIPTION

Top

This is a lh0 decoder -- actually, as lh0 archive is not decoded, this just reads the lh0 body and writes it out.

METHODS

Top

new

creates an object.

decode

reads the lh0 body and writes it out.

AUTHOR

Top

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Top


Archive-Lha documentation Contained in the Archive-Lha distribution.

package Archive::Lha::Decode::LH0;

use strict;
use warnings;
use Carp;
use bytes;
use Archive::Lha::Constants;
use Archive::Lha::CRC;

sub new {
  my ($class, %options) = @_;

  my $header = $options{header};

  my $self  = bless {
    read  => $options{read},
    write => $options{write},
    size  => $header->{encoded_size},
    crc16 => $header->{crc16},
  }, $class;

  $self;
}

sub decode {
  my $self = shift;

  my $crc   = 0;
  my $total = 0;
  my $size  = $self->{size};
  while ( $total < $size ) {
    my $left = $size - $total;
    my $length = ( $left > 4096 ) ? 4096 : $left;
    my $str = $self->{read}->( $length );
    $self->{write}->( $str );
    $crc = Archive::Lha::CRC::update( $crc, $str, length($str) );
    $total += $length;
  }
  return $crc;
}

1;

__END__