Skip to content

Commit 2cf7aff

Browse files
committed
:octocat:
1 parent f20515e commit 2cf7aff

1 file changed

Lines changed: 73 additions & 22 deletions

File tree

README.md

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,79 @@ PHP Extension providing XZ (LZMA2) compression/decompression functions.<br/>
66
[![Linux build](https://github.com/codemasher/php-ext-xz/workflows/Linux/badge.svg)](https://github.com/codemasher/php-ext-xz/actions/workflows/linux.yml)
77
[![Windows PHP8 build](https://github.com/codemasher/php-ext-xz/workflows/Windows/badge.svg)](https://github.com/codemasher/php-ext-xz/actions/workflows/windows.yml)
88

9-
## Build & Installation
9+
## Installation
10+
11+
The recommended way to install the extension is using [PIE](https://github.com/php/pie):
12+
13+
```bash
14+
pie install codemasher/php-ext-xz
15+
```
16+
17+
Windows builds are now done automatically; you can download them from the [releases](https://github.com/codemasher/php-ext-xz/releases).
18+
Copy the `php_xz.dll` into the `/ext` directory of your PHP installation and add the line `extension=xz` to your `php.ini`.
19+
20+
21+
## Basic usage
22+
23+
### String-based operations
24+
25+
You can easily compress and decompress strings.
26+
27+
```php
28+
$string = 'This is a test string that will be compressed and then decompressed.';
29+
30+
// Compress a string
31+
$compressed = xzencode($string);
32+
33+
// Decompress a string
34+
$decompressed = xzdecode($compressed);
35+
```
36+
37+
### File-based operations
38+
39+
The extension also supports stream-based operations for working with `.xz` files.
40+
41+
```php
42+
$file = '/tmp/test.xz';
43+
44+
// Writing to an .xz file
45+
$wh = xzopen($file, 'w');
46+
xzwrite($wh, 'Data to write');
47+
xzclose($wh);
48+
49+
// Reading from an .xz file and outputting its contents
50+
$rh = xzopen($file, 'r');
51+
xzpassthru($rh);
52+
xzclose($rh);
53+
```
54+
55+
56+
## Configuration
57+
58+
You can configure the default compression level and memory limit:
59+
60+
```ini
61+
62+
; Default compression level. Affects `xzencode` and `xzopen`,
63+
; but only when the level was not specified. Values 0-9, default is 5.
64+
xz.compression_level=5
65+
66+
; The maximum amount of memory that can be used when decompressing. Default is 0 (no limit).
67+
xz.max_memory=65536
68+
```
69+
70+
Alternatively, the compression level can be supplied as a parameter to the `xzencode()` and `xzopen()` functions:
71+
72+
```php
73+
const COMPRESSION_LEVEL = 7;
74+
75+
$compressed = xzencode($string, COMPRESSION_LEVEL);
76+
77+
$rh = xzopen($file, 'r', COMPRESSION_LEVEL);
78+
```
79+
80+
81+
## Build from source
1082

1183
### Linux
1284

@@ -28,7 +100,6 @@ sudo make install
28100
Do not forget to add `extension=xz.so` to your `php.ini`.
29101

30102
### Windows
31-
Windows builds are now done automatically on each push; you can download them from the [build artifacts](https://docs.github.com/en/actions/managing-workflow-runs/downloading-workflow-artifacts) or [releases](https://github.com/codemasher/php-ext-xz/releases) (after 1.1.2).
32103

33104
If you want to build it on your own, follow the steps under "[Build your own PHP on Windows](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2)" to setup your build environment.
34105
Before the compilation step, clone this repository to `[...]\php-src\ext\xz` and proceed.
@@ -56,26 +127,6 @@ nmake snap
56127

57128
Please note that the `liblzma` dependency is not included with PHP < 8, so you will need to [download it manually](https://windows.php.net/downloads/php-sdk/deps/vs16/x64/liblzma-5.2.5-vs16-x64.zip) and extract it into the `deps` directory.
58129

59-
Copy the `php_xz.dll` into the `/ext` directory of your PHP installation and add the line `extension=xz` to your `php.ini` or in case of the versioned .dll from the artifacts something like: `extension=xz-0eebbf2-8.2-ts-vs16-x64` - omit the `php_` and `.dll`.
60-
61-
## Basic usage
62-
63-
```php
64-
$fh = xzopen('/tmp/test.xz', 'w');
65-
xzwrite($fh, 'Data you would like compressed and written.');
66-
xzclose($fh);
67-
68-
$fh = xzopen('/tmp/test.xz', 'r');
69-
xzpassthru($fh);
70-
xzclose($fh);
71-
```
72-
73-
```php
74-
$str = 'Data you would like compressed.';
75-
76-
$encoded = xzencode($str);
77-
$decoded = xzdecode($encoded);
78-
```
79130

80131
## Disclaimer
81132
May or may not contain bugs. Use at your own risk.

0 commit comments

Comments
 (0)