summaryrefslogtreecommitdiff
path: root/examples/07-stream_writer.php
diff options
context:
space:
mode:
Diffstat (limited to 'examples/07-stream_writer.php')
-rw-r--r--examples/07-stream_writer.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/07-stream_writer.php b/examples/07-stream_writer.php
new file mode 100644
index 0000000..d94e7ac
--- /dev/null
+++ b/examples/07-stream_writer.php
@@ -0,0 +1,30 @@
+<?php
+declare(strict_types = 1);
+
+require_once __DIR__ . '/../src/ZipStream.php';
+
+# import zipstream classes
+use Pablotron\ZipStream\ZipStream;
+use Pablotron\ZipStream\StreamWriter;
+
+# save as "example.zip" in examples directory
+$zip_path = __DIR__ . '/example.zip';
+
+# open output stream
+$out_stream = fopen($zip_path, 'wb');
+
+# create zipstream
+# NOTE: output archive name is ignored for StreamWriter
+$zip = new ZipStream('', [
+ 'output' => new StreamWriter($out_stream),
+]);
+
+# add a file named "hello.txt" to output archive, containing
+# the string "hello world!"
+$zip->add_file('hello.txt', 'hello world!');
+
+# finalize archive
+$zip->close();
+
+# close output stream
+fclose($out_stream);