| Archive-Lha documentation | Contained in the Archive-Lha distribution. |
Archive::Lha::Stream::Base
This is a base class for ::Stream subclasses.
creates an object, and optionally opens the target.
takes a hash as an argument and does appropriate things for the subclass.
does appropriate things for the subclass.
sees if the position reached end of the file/string/array.
returns the current position.
takes an offset as an argument and sets the position from the top.
takes a length as an argument and returns the chunks of the length (in bytes).
searches for the next lzh header.
Kenichi Ishigaki, <ishigaki@cpan.org>
Copyright (C) 2007 by Kenichi Ishigaki.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Archive-Lha documentation | Contained in the Archive-Lha distribution. |
package Archive::Lha::Stream::Base; use strict; use warnings; use Carp; sub new { my $class = shift; my $self = bless {}, $class; $self->open(@_); $self; } sub open { croak "override" } sub close { return } sub search_header { my $self = shift; my $str = ''; my $count = 0; my $pos = $self->tell; until ( $self->eof ) { $str .= $self->read(1024); my ($method, $level) = $str =~ /.{2}\-(lh[0567])\-.{13}(.)/s; if ( defined $level ) { $level = ord( $level ); if ( $method && $level =~ /^(?:[0-2])$/) { $self->seek( $pos ); return $level; } } $str = substr( $str, -21 ); last if ++$count > 63; # further check would be fruitless } return; } sub eof { my $self = shift; $self->{pos} >= $self->{length}; } sub seek { my ($self, $offset) = @_; $self->{pos} = $offset; } sub tell { shift->{pos} } sub read { croak "override" } 1; __END__