Skip to content

Commit ddb615b

Browse files
committed
test: add dictionary in streams
1 parent 657468f commit ddb615b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/dictionary_streams.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
use dictionary: streams
3+
--SKIPIF--
4+
<?php
5+
if (BROTLI_DICTIONARY_SUPPORT === false) die('skip dictionary not supported');
6+
?>
7+
--FILE--
8+
<?php
9+
include(dirname(__FILE__) . '/data.inc');
10+
$dictionary = file_get_contents(dirname(__FILE__) . '/data.dict');
11+
$file = dirname(__FILE__) . '/data_' . basename(__FILE__, ".php") . '.out';
12+
13+
echo "Compression\n";
14+
15+
$ctx = stream_context_create(
16+
array(
17+
"brotli" => array(
18+
"dict" => $dictionary,
19+
)
20+
)
21+
);
22+
23+
var_dump(file_put_contents('compress.brotli://' . $file, $data, 0, $ctx) == strlen($data));
24+
var_dump($size1 = filesize($file));
25+
var_dump($size1 > 1 && $size1 <= strlen($data));
26+
27+
echo "Decompression\n";
28+
29+
$decomp = file_get_contents('compress.brotli://' . $file, false, $ctx);
30+
var_dump($decomp == $data);
31+
32+
$comp = file_get_contents($file);
33+
$decomp = brotli_uncompress($comp, 0, $dictionary);
34+
var_dump($decomp == $data);
35+
36+
@unlink($file);
37+
?>
38+
===DONE===
39+
--EXPECTF--
40+
Compression
41+
bool(true)
42+
int(%d)
43+
bool(true)
44+
Decompression
45+
bool(true)
46+
bool(true)
47+
===DONE===

0 commit comments

Comments
 (0)