Oihana PHP

gzipFile.php

Table of Contents

Functions

gzipFile()  : string
Compresses a single file with gzip (DEFLATE), streaming it in chunks.

Functions

gzipFile()

Compresses a single file with gzip (DEFLATE), streaming it in chunks.

gzipFile(string $source[, string|null $destination = null ][, int $level = -1 ][, bool $overwrite = true ]) : string

Standalone gzip compression outside of tar archives, using the zlib extension — no subprocess, and the file is never fully loaded into memory.

Parameters
$source : string

Path to the file to compress.

$destination : string|null = null

Output path. Defaults to $source + .gz.

$level : int = -1

Compression level 09, or -1 for zlib's default (default: -1).

$overwrite : bool = true

Whether to overwrite an existing destination (default: true).

Tags
throws
FileException

If the source is invalid, zlib is unavailable, the destination exists and $overwrite is false, or compression fails.

author

Marc Alcaraz (ekameleon)

since
1.2.0
example
use function oihana\files\gzipFile;

gzipFile( '/var/log/app.log' ) ;                 // -> /var/log/app.log.gz
gzipFile( '/data/dump.sql' , '/data/dump.gz' , 9 ) ;
Return values
string

The destination path.

On this page

Search results