1--TEST--
2ZipArchive::getStreamIndex / ZipArchive::getName
3--EXTENSIONS--
4zip
5--FILE--
6<?php
7
8$name = __DIR__ . '/getstream.zip';
9
10$zip = new ZipArchive;
11$r = $zip->open($name, ZIPARCHIVE::CREATE);
12$zip->addFromString('foo.txt', 'foo');
13$zip->addFromString('bar.txt', 'bar');
14$zip->close();
15
16$r = $zip->open($name);
17
18$zip->addFromString('bar.txt', 'baz', ZipArchive::FL_OVERWRITE);
19
20
21echo "== Name\n";
22$fp = $zip->getStreamName('foo.txt');
23var_dump($zip->status);
24var_dump(stream_get_contents($fp));
25$zip->clearError();
26fclose($fp);
27
28echo "== Index\n";
29$fp = $zip->getStreamIndex(0);
30var_dump($zip->status);
31var_dump(stream_get_contents($fp));
32$zip->clearError();
33fclose($fp);
34
35echo "== Index, changed\n";
36$fp = $zip->getStreamIndex(1);
37if (version_compare(ZipArchive::LIBZIP_VERSION, "1.10.0", "<")) {
38	/* not supported in old version */
39	var_dump($zip->status === ZipArchive::ER_CHANGED);
40} else {
41	var_dump($zip->status === 0 && stream_get_contents($fp) === "baz");
42}
43$zip->clearError();
44
45echo "== Index, unchanged\n";
46$fp = $zip->getStreamIndex(1, ZipArchive::FL_UNCHANGED);
47var_dump($zip->status === 0 && stream_get_contents($fp) === "bar");
48$zip->clearError();
49fclose($fp);
50
51$zip->close();
52?>
53== Done
54--CLEAN--
55<?php
56$name = __DIR__ . '/getstream.zip';
57@unlink($name);
58?>
59--EXPECTF--
60== Name
61int(0)
62string(3) "foo"
63== Index
64int(0)
65string(3) "foo"
66== Index, changed
67bool(true)
68== Index, unchanged
69bool(true)
70== Done
71