| Archive-Lha documentation | Contained in the Archive-Lha distribution. |
Archive::Lha::Stream::File
my $stream = Archive::Lha::Stream::File->new; $stream->open( file => 'some.lzh' ); # equivalent my $stream = Archive::Lha::Stream::File->new( file => 'some.lzh' );
This is a thin wrapper for the builtin I/O functions.
creates an object, and optionally opens an archive file.
takes a hash as an argument and opens a specified file, locks it, and makes it raw, binary mode.
closes the file.
sees if the file reached end of file.
returns the current position.
takes an offset as an argument and sets the position from the file top.
takes a length as an argument and returns the chunks of the length (in bytes) from the file.
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::File; use strict; use warnings; use Carp; use Fcntl qw( :flock :seek ); use base qw( Archive::Lha::Stream::Base ); sub open { my ($self, %options) = @_; open my $fh, '<:raw', $options{file} or croak "Can't open $options{file}: $!"; flock $fh, LOCK_SH or croak "Can't lock $options{file}: $!"; binmode $fh; $self->{fh} = $fh; } sub close { my $self = shift; close $self->{fh}; delete $self->{fh}; } sub eof { my $self = shift; eof $self->{fh}; } sub seek { my ($self, $offset) = @_; seek $self->{fh}, $offset, SEEK_SET; } sub tell { my ($self, $offset) = @_; tell $self->{fh}; } sub read { my ($self, $length) = @_; read $self->{fh}, ( my $chunk ), $length; return $chunk; } 1; __END__