xref: /PHP-8.2/ext/zip/tests/oo_stream_seek.phpt (revision 2223853c)
1--TEST--
2getStream and seek
3--EXTENSIONS--
4zip
5--SKIPIF--
6<?php
7if(version_compare(ZipArchive::LIBZIP_VERSION, '1.9.1', '<')) die('skip libzip < 1.9.1');
8?>
9--FILE--
10<?php
11var_dump(ZipArchive::LIBZIP_VERSION);
12$file = __DIR__ . '/test.zip';
13$zip = new ZipArchive;
14if (!$zip->open($file)) {
15	exit('failed');
16}
17echo "+ ZipArchive::getStream\n";
18$fp = $zip->getStream('bar');
19if(!$fp) exit("\n");
20var_dump($fp);
21
22var_dump(fseek($fp, 1, SEEK_SET));
23var_dump(fread($fp, 2));
24var_dump(ftell($fp));
25var_dump(fseek($fp, 0, SEEK_SET));
26var_dump(fread($fp, 2));
27var_dump(ftell($fp));
28
29fclose($fp);
30
31echo "+ ZipArchive::getStream no supported\n";
32$fp = $zip->getStream('entry1.txt');
33if(!$fp) exit("\n");
34var_dump($fp);
35
36var_dump(fseek($fp, 2, SEEK_SET));
37var_dump(fread($fp, 2));
38fclose($fp);
39
40$zip->close();
41
42
43echo "+ Zip Stream\n";
44$fp = fopen('zip://' . __DIR__ . '/test.zip#bar', 'rb');
45if(!$fp) exit("\n");
46var_dump($fp);
47var_dump(fseek($fp, 1, SEEK_SET));
48var_dump(fread($fp, 2));
49var_dump(ftell($fp));
50var_dump(fseek($fp, 0, SEEK_SET));
51var_dump(fread($fp, 2));
52var_dump(ftell($fp));
53fclose($fp);
54
55?>
56--EXPECTF--
57string(%d) "%s"
58+ ZipArchive::getStream
59resource(%d) of type (stream)
60int(0)
61string(2) "ar"
62int(3)
63int(0)
64string(2) "ba"
65int(2)
66+ ZipArchive::getStream no supported
67resource(%d) of type (stream)
68
69Warning: fseek(): %s does not support seeking in %s
70int(-1)
71string(2) "en"
72+ Zip Stream
73resource(%d) of type (stream)
74int(0)
75string(2) "ar"
76int(3)
77int(0)
78string(2) "ba"
79int(2)
80