/php-ext-xz

XZ Extension for PHP

Primary LanguagePHPMIT LicenseMIT

XZ Extension for PHP

Build Status

This extension allows XZ (liblzma).

Documentation for XZ can be found at » https://tukaani.org/xz.

Build from sources

% git clone --depth=1 https://github.com/kjdev/php-ext-xz.git
% phpize
% ./configure
% make
% make install

You need to install xz-devel using dnf/yum (Fedora, RHEL, CentOS...), or liblzma-dev using apt-get or aptitude (Debian, Ubuntu...)

Configration

php.ini:

extension=xz.so

Constant

Name Description
XZ_COMPRESS_LEVEL_MIN Minimal compress level value
XZ_COMPRESS_LEVEL_MAX Maximal compress level value
XZ_COMPRESS_LEVEL_DEFAULT Default compress level value

Function

  • xz_compress — XZ compression
  • xz_uncompress — XZ decompression

xz_compress — XZ compression

Description

string xz_compress ( string $data [, int $level = 6 ] )

XZ compression.

Pameters

  • data

    The string to compress.

  • level

    The level of compression (0-9). (Defaults to 6)

Return Values

Returns the compressed data or FALSE if an error occurred.

xz_uncompress — XZ decompression

Description

string xz_uncompress ( string $data )

XZ decompression.

Alias: xz_decompress

Pameters

  • data

    The compressed string.

Return Values

Returns the decompressed data or FALSE if an error occurred.

Namespace

Namespace Xz;

function compress( $data [, $level = 6 ] )
function uncompress( $data )

xz_compress and xz_uncompress function alias.

Streams

XZ compression and uncompression are available using the compress.xz:// stream prefix.

Examples

// Using functions
$data = xz_compress('test');
xz_uncompress($data);

// Using namespaced functions
$data = \Xz\compress('test');
\Xz\uncompress($data);

// Using streams
file_put_contents('compress.xz:///patch/to/data.xz', $data);
readfile('compress.xz:///patch/to/data.xz');