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


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

Index


Code Index:

NAME

Top

Archive::Lha::Decode

SYNOPSIS

Top

  # don't forget :raw, or eol might be converted implicitly
  open my $fh, '>:raw', $header->pathname;
  binmode $fh;
  $stream->seek( $header->data_top );
  my $decoder = Archive::Lha::Decode->new(
    header => $header,
    read   => sub { $stream->read(@_) },
    write  => sub { print $fh @_ },
  )
  my $crc16 = $decoder->decode;
  croak "crc mismatch" if $crc16 != $header->crc16;

DESCRIPTION

Top

This is used to decode/extract an archived file from the stream. Actually this ::Decode class is a factory and decoding is done by a delegated class according to the header's "method" property.

All of the ::Decode subclasses require read/write callbacks. Read callback should take a byte length as an argument, and return the bytes of the length from a file or a string. Write callback should take a part of the decoded (probably binary) string as an argument, and the rest is up to you. You may want to write it down in a file as shown above, or maybe append it to a string to store in a database after finished. You may want to encode it first, or throw it away if the string contains unprintable binary. You may want to use a temporary file. You may want to update a progress indicator. Do whatever you want.

METHODS

Top

new

takes an Archive::Lha::Header object, and read/write callbacks and creates an appropriate object.

decode

does the decoding stuff and returns CRC-16 of the decoded string. The decoded string itself is passed to the write callback while decoding (step by step).

AUTHOR

Top

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Top


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

package Archive::Lha::Decode;

use strict;
use warnings;
use Carp;

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

  croak "Header is missing" unless defined $options{header};

  my $method = uc $options{header}->method;

  my $package = 'Archive::Lha::Decode::'.$method;

  eval "require $package;";
  croak "Can't load decoder: $@" if $@;

  return $package->new( %options );
}

1;

__END__