Extract
=title class Zef::Extract
=subtitle A configurable implementation of the Extractor interface
Synopsis
use Zef;
use Zef::Extract;
# Setup with a single extractor backend
my $extractor = Zef::Extract.new(
backends => [
{ module => "Zef::Service::Shell::tar" },
],
);
# Save the content of $uri to $save-to
my $tar-file = $*CWD.add("zef-v0.9.4.tar.gz");
my $candidate = Candidate.new(uri => $tar-file);
my $extract-to = $*CWD.add("my-extract-dir");
# Show what files an archive contains
say "About to extract the following paths:";
say "\t{$_}" for $extractor.ls-files($candidate);
# Extract the archive
my $extracted-to = $extractor.extract($candidate, $extract-to);
say $extracted-to ?? "Done" !! "Something went wrong...";
Description
An Extractor that uses 1 or more other Extractor instances as backends. It abstracts the logic
to do 'extract this path with the first backend that supports the given path'.
Methods
method extract-matcher
method extract-matcher($path --> Bool:D)
Returns True if any of the probeable self.plugins know how to extract $path.
method extract
method extract(Candidate $candi, IO() $extract-to, Supplier :$logger, Int :$timeout --> IO::Path)
Extracts the files for $candi (usually as $candi.uri) to $extract-to. If a backend fails to extract
for some reason (such as going over its :$timeout) the next matching backend will be used. Failure occurs
when no backend was able to extract the $candi.
An optional :$logger can be supplied to receive events about what is occurring.
An optional :$timeout can be passed to denote the number of seconds after which we'll assume failure.
On success it returns the IO::Path where the data was actually extracted to. On failure it returns Nil.
Note this differs from other 'Extractor' adapters method fetch (i.e. the extractors this uses as backends) which
take a Str $uri as the first parameter, not a Candidate $candi.
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.