Archive::SevenZip - Read/write 7z , zip , ISO9960 and other archives
my $ar = Archive::SevenZip->new(
find => 1,
archivename => $archivename,
verbose => $verbose,
);
for my $entry ( $ar->list ) {
my $target = join "/", "$target_dir", $entry->basename;
$ar->extractMember( $entry->fileName, $target );
};
my $version = Archive::SevenZip->find_7z_executable()
or die "No 7z found.";
print "Found 7z version '$version'";
Finds the 7z executable in the path or in $ENV{ProgramFiles}
or $ENV{ProgramFiles(x86)}
. This is called
when a Archive::SevenZip
instance is created with the find
parameter set to 1.
If $ENV{PERL_ARCHIVE_SEVENZIP_BIN}
is set, this value will be used as
the 7z executable and the path will not be searched.
my $ar = Archive::SevenZip->new( $archivename );
my $ar = Archive::SevenZip->new(
archivename => $archivename,
find => 1,
);
Creates a new class instance.
find
- will try to find the executable using ->find_7z_executable
my @entries = $ar->open;
for my $entry (@entries) {
print $entry->fileName, "\n";
};
Lists the entries in the archive. A fresh archive which does not exist on disk yet has no entries. The returned entries are Archive::SevenZip::Entry instances.
This method will one day move to the Path::Class-compatibility API.
my $entry = $ar->memberNamed('hello_world.txt');
print $entry->fileName, "\n";
The path separator must be a forward slash ("/")
This method will one day move to the Archive::Zip-compatibility API.
my $fh = $ar->openMemberFH('test.txt');
while( <$fh> ) {
print "test.txt: $_";
};
Reads the uncompressed content of the member from the archive.
This method will one day move to the Archive::Zip-compatibility API.
$ar->extractMember('test.txt' => 'extracted_test.txt');
Extracts the uncompressed content of the member from the archive.
This method will one day move to the Archive::Zip-compatibility API.
$ar->removeMember('test.txt');
Removes the member from the archive.
$ar->add_scalar( "Some name.txt", "This is the content" );
Adds a scalar as an archive member.
Unfortunately, 7zip only reads archive members from STDIN for xz, lzma, tar, gzip and bzip2 archives. In the other cases, the scalar will be written to a tempfile, added to the archive and then renamed in the archive.
This requires 7zip version 9.30+
$ar->add_directory( "real_etc", "etc" );
Adds an empty directory
This currently ignores the directory date and time if the directory exists
$ar->add( items => ["real_etc" => "name_in_archive" ] );
Adds elements to an archive
This currently ignores the directory date and time if the directory exists
my $ar = Archive::SevenZip->archiveZipApi(
find => 1,
archivename => $archivename,
verbose => $verbose,
);
print "$_\n" for $ar->list_files;
This is an alternative constructor that gives you an API that is somewhat compatible with the API of Archive::Zip. See also Archive::SevenZip::API::ArchiveZip.
my $ar = Archive::SevenZip->archiveTarApi(
find => 1,
archivename => $archivename,
verbose => $verbose,
);
print "$_\n" for $ar->list_files;
This is an alternative constructor that gives you an API that is somewhat compatible with the API of Archive::Tar. See also Archive::SevenZip::API::ArchiveTar.
Path::Class::Archive::Handle - treat archives as directories
This module tries to mimic the API of Archive::Zip in some cases and in other cases, the API of Path::Class. It is also a very rough draft that just happens to be doing what I need, mostly extracting files.
File::Unpack - also supports unpacking from 7z archives
Compress::unLZMA - uncompressor for the LZMA compression method used by 7z
The public repository of this module is https://github.com/Corion/archive-sevenzip.
The public support forum of this module is https://perlmonks.org/.
Please report bugs in this module via the RT CPAN bug queue at https://rt.cpan.org/Public/Dist/Display.html?Name=Archive-SevenZip or via mail to archive-sevenzip-Bugs@rt.cpan.org.
Max Maischein corion@cpan.org
Copyright 2015-2024 by Max Maischein corion@cpan.org
.
This module is released under the same terms as Perl itself.