Changeset 3588 for lang/perl/Archive-Lha/trunk/lib/Archive/Lha/Decode.pm
- Timestamp:
- 12/26/07 12:00:47 (13 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Archive-Lha/trunk/lib/Archive/Lha/Decode.pm
r3270 r3588 10 10 croak "Header is missing" unless defined $options{header}; 11 11 12 my $method = uc $options{header}-> {method};12 my $method = uc $options{header}->method; 13 13 14 14 my $package = 'Archive::Lha::Decode::'.$method; … … 30 30 =head1 SYNOPSIS 31 31 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 32 44 =head1 DESCRIPTION 33 45 46 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. 47 48 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. 49 34 50 =head1 METHODS 51 52 =head2 new 53 54 takes an Archive::Lha::Header object, and read/write callbacks and creates an appropriate object. 55 56 =head2 decode 57 58 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). 35 59 36 60 =head1 AUTHOR
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)