tarDirectory.php
Table of Contents
Functions
- tarDirectory() : string
- Creates a tar archive from a directory with specified compression.
Functions
tarDirectory()
Creates a tar archive from a directory with specified compression.
tarDirectory(string $directory[, string|null $compression = CompressionType::GZIP ][, string|null $outputPath = null ][, array<string|int, mixed> $options = [] ]) : string
This function creates a compressed (or uncompressed) tar archive from
the given directory. It supports filtering files by exclude patterns,
by a callback filter function, and adding optional metadata saved as
.metadata.json
inside the archive.
If no filters or metadata are provided, it simply creates the archive directly from the directory. Otherwise, it copies filtered files to a temporary directory and archives from there.
Parameters
- $directory : string
-
The source directory to archive.
- $compression : string|null = CompressionType::GZIP
-
Compression type (e.g. gzip, bzip2, none). Default is gzip compression.
- $outputPath : string|null = null
-
Optional output archive path. If null, defaults to directory name plus extension based on compression.
- $options : array<string|int, mixed> = []
-
Additional options:
- exclude => string[] list of glob patterns or file names to exclude
- filter => callable|null a function (string $filepath): bool
- metadata => array<string, string> extra metadata to embed in
.metadata.json
Tags
Return values
string —Returns the full path to the created archive file.