summaryrefslogtreecommitdiff
path: root/examples/12-add_file_methods.php
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-03 07:12:40 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 09:54:53 -0400
commiteca42d118e439dc0f3796650e8a68992d513f8ee (patch)
treed6f0a74dbe3a7cee63760afbb8f98505f80f8677 /examples/12-add_file_methods.php
parent5dda6b1011472e558e3fd9c744c2fd537528b115 (diff)
downloadzipstream-php-eca42d118e439dc0f3796650e8a68992d513f8ee.tar.bz2
zipstream-php-eca42d118e439dc0f3796650e8a68992d513f8ee.zip
add examples/{10,11,12,13}*php, add examples/*zip to .gitignore
Diffstat (limited to 'examples/12-add_file_methods.php')
-rw-r--r--examples/12-add_file_methods.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/12-add_file_methods.php b/examples/12-add_file_methods.php
new file mode 100644
index 0000000..def5425
--- /dev/null
+++ b/examples/12-add_file_methods.php
@@ -0,0 +1,32 @@
+<?php
+declare(strict_types = 1);
+
+require_once __DIR__ . '/../src/ZipStream.php';
+
+# import zipstream classes
+use Pablotron\ZipStream\ZipStream;
+use Pablotron\ZipStream\FileWriter;
+use Pablotron\ZipStream\Methods;
+
+# output zip file
+$zip_path = __DIR__ . '/example-12.zip';
+
+# output options
+$zip_args = [
+ 'output' => new FileWriter(),
+];
+
+# create archive in this directory with a comment
+ZipStream::send($zip_path, function(ZipStream &$zip) {
+ # add "hello.txt" to output using the STORE method
+ $zip->add_file('hello.txt', 'hello world!', [
+ # use STORE method (e.g., no compression)
+ 'method' => Methods::STORE,
+ ]);
+
+ # add "hola.txt" to output using the DEFLATE method
+ $zip->add_file('hola.txt', 'hola!!', [
+ # use DEFLATE method (e.g., compressed)
+ 'method' => Methods::DEFLATE,
+ ]);
+}, $zip_args);