tar
=title class Zef::Service::Shell::tar
=subtitle A tar based implementation of the Extractor interface
Synopsis
use Zef;
use Zef::Service::Shell::tar;
my $tar = Zef::Service::Shell::tar.new;
# Assuming a zef-main.tar.gz file is in the cwd...
my $source = $*HOME.child("zef-main.tar.gz");
my $extract-to = $*TMPDIR.child(time);
my $extracted-to = $tar.extract($source, $extract-to);
die "Something went wrong" unless $extracted-to;
say "Zef META6 from HEAD: ";
say $extracted-to.child("zef-main/META6.json").slurp;
Description
Extractor class for handling file based URIs ending in .tar.gz / .tgz using the tar command. If bsdtar is
used it will also work on .zip files.
You probably never want to use this unless its indirectly through Zef::Extract;
handling files and spawning processes will generally be easier using core language functionality. This
class exists to provide the means for fetching a file using the Extractor interfaces that the e.g. git/unzip
adapters use.
Methods
method probe
method probe(--> Bool:D)
Returns True if this module can successfully launch the tar command.
method extract-matcher
method extract-matcher(Str() $uri --> Bool:D)
Returns True if this module knows how to extract $uri, which it decides based on if $uri is
an existing local file and ends with .tar.gz or .tgz. If bsdtar is used it will also work on
.zip files.
method extract
method extract(IO() $archive-file, IO() $extract-to, Supplier :$stdout, Supplier :$stderr --> IO::Path)
Extracts the files in $archive-file to $save-to via the tar command. A Supplier can be supplied
as :$stdout and :$stderr to receive any output.
On success it returns the IO::Path where the data was actually extracted to. On failure it returns Nil.
method ls-files
method ls-files(IO() $archive-file --> Array[Str])
On success it returns an Array of relative paths that are available to be extracted from $archive-file.