Oihana PHP

tarWithBinary.php

Table of Contents

Functions

tarWithBinary()  : void
Builds an archive with the system `tar`.
tarCompressionFlag()  : string|null
Whether the system tar can produce this compression, and with which flag.
tarCompressorExists()  : bool
Whether the compressor `tar` would shell out to is installed.
tarBinaryHandles()  : bool
Whether the binary engine can take this archive on.

Functions

tarWithBinary()

Builds an archive with the system `tar`.

tarWithBinary(string $binary, array<int, array{base: string, name: string, directory: bool, path: string}> $entries, string $finalPath, string $compression) : void

The entry names are computed in PHP by tarEntries() and handed over verbatim, with --no-recursion, so tar walks nothing and decides nothing: it writes exactly the list it is given, under exactly the names PharData would have used. That is what keeps archives written by either engine interchangeable.

The list travels on standard input, NUL-separated. Passed as arguments it would break on any real site — a stock WordPress install is sixteen thousand paths, far past ARG_MAX — and NUL separation is the only form that survives newlines and quotes in filenames.

Parameters
$binary : string

The tar to run.

$entries : array<int, array{base: string, name: string, directory: bool, path: string}>

What to archive.

$finalPath : string

Where the archive goes.

$compression : string

A CompressionType value.

Tags
throws
RuntimeException

If tar cannot be started, or refuses the archive.

author

Marc Alcaraz (ekameleon)

since
1.3.0

tarCompressionFlag()

Whether the system tar can produce this compression, and with which flag.

tarCompressionFlag(string $compression) : string|null
Parameters
$compression : string

A CompressionType value.

Tags
author

Marc Alcaraz (ekameleon)

since
1.3.0
Return values
string|null

The flag, null for an uncompressed archive.

tarCompressorExists()

Whether the compressor `tar` would shell out to is installed.

tarCompressorExists(string $compression) : bool

tar does not compress: it pipes through gzip, bzip2, xz. PharData does it in PHP, through the bundled extensions — so a machine with ext-bz2 and no bzip2 program used to produce a bzip2 archive and would stop. Asked before the engine is chosen, so that host keeps the engine that works for it instead of receiving an error where it had a file.

Parameters
$compression : string

A CompressionType value.

Tags
author

Marc Alcaraz (ekameleon)

since
1.3.0
Return values
bool

True when nothing external is needed, or when what is needed is there.

tarBinaryHandles()

Whether the binary engine can take this archive on.

tarBinaryHandles(array<int, array{base: string, name: string, directory: bool, path: string}> $entries, string $compression) : bool

It takes the ones it can reproduce exactly, and leaves the rest to PharData — decided before anything is written, never after something has failed.

Archiving several paths that do not share a parent needs one tar invocation per parent, and an archive cannot be appended to once compressed. That case is rare — it means passing unrelated paths with no preserveRoot — and PharData already handles it correctly, so it stays there rather than justifying a second, less-travelled code path.

Parameters
$entries : array<int, array{base: string, name: string, directory: bool, path: string}>
$compression : string
Tags
author

Marc Alcaraz (ekameleon)

since
1.3.0
Return values
bool
On this page

Search results