Show
Ignore:
Timestamp:
12/26/07 12:00:47 (13 months ago)
Author:
charsbar
Message:

lang/perl/Archive-Lha: lots of changes, cleanups, pods and 0.02 -> CPAN

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Archive-Lha/trunk/lib/Archive/Lha/Decode.pm

    r3270 r3588  
    1010  croak "Header is missing" unless defined $options{header}; 
    1111 
    12   my $method = uc $options{header}->{method}; 
     12  my $method = uc $options{header}->method; 
    1313 
    1414  my $package = 'Archive::Lha::Decode::'.$method; 
     
    3030=head1 SYNOPSIS 
    3131 
     32  # don't forget :raw, or eol might be converted implicitly 
     33  open my $fh, '>:raw', $header->pathname; 
     34  binmode $fh; 
     35  $stream->seek( $header->data_top ); 
     36  my $decoder = Archive::Lha::Decode->new( 
     37    header => $header, 
     38    read   => sub { $stream->read(@_) }, 
     39    write  => sub { print $fh @_ }, 
     40  ) 
     41  my $crc16 = $decoder->decode; 
     42  croak "crc mismatch" if $crc16 != $header->crc16; 
     43 
    3244=head1 DESCRIPTION 
    3345 
     46This 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. 
     47 
     48All 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. 
     49 
    3450=head1 METHODS 
     51 
     52=head2 new 
     53 
     54takes an Archive::Lha::Header object, and read/write callbacks and creates an appropriate object. 
     55 
     56=head2 decode 
     57 
     58does 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). 
    3559 
    3660=head1 AUTHOR