forked from udan11/php-xz
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxzcode_advanced.phpt
58 lines (50 loc) · 1002 Bytes
/
xzcode_advanced.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--TEST--
Test `xzencode` and `xzdecode`: big inputs.
--SKIPIF--
<?php
if (!extension_loaded("xz")) {
print("XZ extension is not loaded!");
}
?>
--FILE--
<?php
/**
* The size of the chunk that is going to be repeated.
* @var int
*/
$chunkSize = 1 * 1024 * 1024; // 1 MB
/**
* The number of chunks.
* @var integer
*/
$chunkNumber = 8; // 256 chunks of 1 MB = 256 MB
/**
* A random chunk of data.
* @var string
*/
$chunk = '';
// Generating a random chunk.
for ($i = 0; $i < $chunkSize; ++$i) {
$chunk .= chr(rand(0, 255)); // adds one random byte
}
/**
* A random string of size `$size`.
* @var string
*/
$str = '';
// Generating a random string.
for ($i = 0; $i < $chunkNumber; ++$i) {
$str .= $chunk;
}
var_dump(($chunkSize * $chunkNumber) === strlen($str));
$encoded = xzencode($str);
print("encoding finished\n");
$decoded = xzdecode($encoded);
print("decoding finished\n");
var_dump($str === $decoded);
?>
--EXPECTF--
bool(true)
encoding finished
decoding finished
bool(true)