Archive::Lha::Stream::File - Archive::Lha::Stream::File documentation


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

Index


Code Index:

NAME

Top

Archive::Lha::Stream::File

SYNOPSIS

Top

  my $stream = Archive::Lha::Stream::File->new;
  $stream->open( file => 'some.lzh' );

  # equivalent
  my $stream = Archive::Lha::Stream::File->new( file => 'some.lzh' );

DESCRIPTION

Top

This is a thin wrapper for the builtin I/O functions.

METHODS

Top

new

creates an object, and optionally opens an archive file.

open

takes a hash as an argument and opens a specified file, locks it, and makes it raw, binary mode.

close

closes the file.

eof

sees if the file reached end of file.

tell

returns the current position.

seek

takes an offset as an argument and sets the position from the file top.

read

takes a length as an argument and returns the chunks of the length (in bytes) from the file.

search_header

searches for the next lzh header.

SEE ALSO

Top

Archive::Lha::Stream

AUTHOR

Top

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Top


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__