Archive-SevenZip

 view release on metacpan or  search on metacpan

lib/Archive/SevenZip/API/ArchiveZip.pm  view on Meta::CPAN

package Archive::SevenZip::API::ArchiveZip;
use strict;
use warnings;
use Carp qw(croak);
use Encode qw( decode encode );
use File::Basename qw(dirname basename);
use File::Copy;
use Archive::SevenZip 'AZ_OK';

our $VERSION= '0.19';

sub new {
    my( $class, %options )= @_;
    $options{ sevenZip } = Archive::SevenZip->new();
    bless \%options => $class;
};

sub sevenZip { $_[0]->{sevenZip} }

=head1 NAME

Archive::SevenZip::API::ArchiveZip - Archive::Zip compatibility API

=head1 SYNOPSIS

  my $ar = Archive::SevenZip->archiveZipApi(
      find => 1,
      archivename => $archivename,
      verbose => $verbose,
  );

This module implements just enough of the L<Archive::Zip>
API to pass some of the Archive::Zip test files. Ideally you can
use this API to enable a script that uses Archive::Zip
to also read other archive files supported by 7z.

=cut

# Helper to decode the hashref/named API
sub _params {
    my( $args, @names ) = @_;
    if( ref $args->[1] eq 'HASH' ) {
        return( $args->[0], @{ $args }{ @names } )
    } else {
        return @$args
    }
}

sub read {
    my( $self, $filename ) = _params(\@_, qw(filename));
    $self->sevenZip->{archivename} = $filename;
    return AZ_OK;
}

sub writeToFileNamed {
    my( $self, $targetName ) = _params(\@_, qw(fileName));

    my $source = $self->sevenZip->archive_or_temp;
    copy( $source, $targetName );
    return AZ_OK;
}

sub addFileOrDirectory {
    my($self, $name, $newName, $compressionLevel)
        = _params(\@_, qw(name zipName compressionLevel));
    $newName = $name
        unless defined $newName;
    $self->sevenZip->add(
        items => [ [$name, $newName] ],
        compression => $compressionLevel
    );
}

sub addString {
    my( $self, $content, $name, %options )

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.638 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )