aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-02 13:40:44 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 09:54:40 -0400
commit00488262cff699007da20a56e008fb079f25acd3 (patch)
treedb2e6429f8ea9cfd9d628017b5b70c7890de1943 /examples
parentc6485275e8ccf50ae6adf6a7f5ed7519e8145406 (diff)
downloadzipstream-php-00488262cff699007da20a56e008fb079f25acd3.tar.bz2
zipstream-php-00488262cff699007da20a56e008fb079f25acd3.zip
add StreamWriter
Diffstat (limited to 'examples')
-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);