Skip to content
PHP Ecosystem
Explore

TarballExtractor

API reference › Foxy › Native › TarballExtractor

final readonly classFoxy\Native\TarballExtractor
Sourcesrc/Native/TarballExtractor.php

Extracts an npm package tarball (gzip-compressed or plain tar) into a directory, stripping the first path component.

Reads POSIX ustar, PAX extended headers (path and size records) and GNU long names. Directories and regular files are created; symbolic links, hard links and unknown entry types are skipped. A file whose mode carries an execute bit is made executable (0755); modification times are not preserved.

See also: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/pax.html.

MethodDescriptionDefined by
__construct()Creates a tarball extractor using Composer’s filesystem abstraction.TarballExtractor
extract()Extracts the tarball into the destination directory, creating it first.TarballExtractor
public function __construct(Composer\Util\Filesystem $fs)

Creates a tarball extractor using Composer’s filesystem abstraction.

Parameters

ParameterTypeDescription
$fsComposer\Util\FilesystemFilesystem used to create directories.
public function extract(string $tarball, string $destination, string $label): void

Extracts the tarball into the destination directory, creating it first.

Parameters

ParameterTypeDescription
$tarballstringPath of the .tgz (or plain .tar) file.
$destinationstringDirectory that receives the package contents.
$labelstringName of the tarball used in error messages, the tarball URL in production.

Throws

  • Foxy\Exception\RuntimeException: if the tarball cannot be opened, is not a valid ustar archive, is truncated, holds an entry outside the package directory, or an entry cannot be written.