VFSsimple::Drv::Iso - A VFSsimple implementation over ISO9660 fs


VFSsimple-Drv-Iso documentation Contained in the VFSsimple-Drv-Iso distribution.

Index


Code Index:

NAME

Top

VFSsimple::Drv::Iso - A VFSsimple implementation over ISO9660 fs

DESCRIPTION

Top

This module provide access method for VFSsimple module to access to files inside ISO9660 CD image.

Access is provide using Device::Cdio::ISO9660 module.

SEE ALSO

Top

VFSsimple

LICENSE AND COPYRIGHT

Top


VFSsimple-Drv-Iso documentation Contained in the VFSsimple-Drv-Iso distribution.
package VFSsimple::Drv::Iso;

use strict;
use warnings;
use Device::Cdio::ISO9660;
use Device::Cdio::ISO9660::IFS ();
use File::Temp qw(tempfile);
use POSIX;
use base qw(VFSsimple::Base);

our $VERSION = '0.03';

sub drv_new {
    my ($self) = @_;
    my $iso = Device::Cdio::ISO9660::IFS->new(-source => $self->archive_path);
    $self->{iso} = $iso or return;
    $self->{prefix} = $self->archive_subpath || '';

    return $iso ? $self : ();
}

sub drv_copy {
    my ($self, $src, $dest) = @_;
    open(my $fh, '>', $dest) or return;
    my $iso = $self->{iso};
    my $stat = $iso->stat("$self->{prefix}/$src", 0) or return;
    if ($stat) {
        my $blocks = POSIX::ceil($stat->{size} / $perlcdio::ISO_BLOCKSIZE);
        for (my $i = 0; $i < $blocks; $i++) {
            my $lsn = $stat->{LSN} + $i;
            my $buf = $iso->seek_read ($lsn);
            if (defined($buf)) {
                print $fh (($i + 1) * $perlcdio::ISO_BLOCKSIZE > $stat->{size}) ?
                    substr($buf, 0, $stat->{size} - ($i + 1) * $perlcdio::ISO_BLOCKSIZE) :
                    $buf;

            } else {
                return;
            }
        }
    }
    close($fh);
    return $dest;
}

sub drv_stat {
    my ($self, $file) = @_;
    my $iso = $self->{iso};
    return(defined($iso->stat("$self->{prefix}/$file", 0)));
}

1;

__END__