diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | examples/01-simple.php | 3 | ||||
-rw-r--r-- | examples/10-archive_comment.php | 20 | ||||
-rw-r--r-- | examples/11-add_file_comment.php | 23 | ||||
-rw-r--r-- | examples/12-add_file_methods.php | 32 | ||||
-rw-r--r-- | examples/13-add_file_times.php | 32 |
6 files changed, 110 insertions, 1 deletions
@@ -1,3 +1,4 @@ *.sw? vendor/ docs/ +examples/*zip diff --git a/examples/01-simple.php b/examples/01-simple.php index a01e0f8..7b4d450 100644 --- a/examples/01-simple.php +++ b/examples/01-simple.php @@ -6,9 +6,10 @@ require_once __DIR__ . '/../src/ZipStream.php'; use Pablotron\ZipStream\ZipStream; # create the output stream +# this will send the archive as an HTTP response by default $zip = new ZipStream('example.zip'); -# add a file named "hello.txt" to output archive, containing +# add "hello.txt" to output archive, containing # the string "hello world!" $zip->add_file('hello.txt', 'hello world!'); diff --git a/examples/10-archive_comment.php b/examples/10-archive_comment.php new file mode 100644 index 0000000..cc68f2d --- /dev/null +++ b/examples/10-archive_comment.php @@ -0,0 +1,20 @@ +<?php +declare(strict_types = 1); + +require_once __DIR__ . '/../src/ZipStream.php'; + +# import zipstream classes +use Pablotron\ZipStream\ZipStream; +use Pablotron\ZipStream\FileWriter; + +$zip_path = __DIR__ . '/example-10.zip'; + +# create archive in this directory with a comment +ZipStream::send($zip_path, function(ZipStream &$zip) { + # add a file named "hello.txt" to output archive, containing + # the string "hello world!" + $zip->add_file('hello.txt', 'hello world!'); +}, [ + 'comment' => 'example archive comment', + 'output' => new FileWriter(), +]); diff --git a/examples/11-add_file_comment.php b/examples/11-add_file_comment.php new file mode 100644 index 0000000..84bd71b --- /dev/null +++ b/examples/11-add_file_comment.php @@ -0,0 +1,23 @@ +<?php +declare(strict_types = 1); + +require_once __DIR__ . '/../src/ZipStream.php'; + +# import zipstream classes +use Pablotron\ZipStream\ZipStream; +use Pablotron\ZipStream\FileWriter; + +# output zip file +$zip_path = __DIR__ . '/example-11.zip'; + +$zip_args = [ + 'output' => new FileWriter(), +]; + +# create archive in this directory with a comment +ZipStream::send($zip_path, function(ZipStream &$zip) { + # add a file "hello.txt" to output with a comment + $zip->add_file('hello.txt', 'hello world!', [ + 'comment' => 'hello this is a comment!', + ]); +}, $zip_args); 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); diff --git a/examples/13-add_file_times.php b/examples/13-add_file_times.php new file mode 100644 index 0000000..bf226b3 --- /dev/null +++ b/examples/13-add_file_times.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; + +# output zip path +$zip_path = __DIR__ . '/example-13.zip'; + +# output options +$zip_args = [ + 'output' => new FileWriter(), +]; + +# create archive in this directory with a comment +ZipStream::send($zip_path, function(ZipStream &$zip) { + # get current time + $time = time(); + + # add "hello.txt" to output with a time of 2 hours ago + $zip->add_file('hello.txt', 'hello world!', [ + 'time' => $time - (2 * 3600), + ]); + + # add "hola.txt" to output with a time of 2 hours in the future + $zip->add_file('hola.txt', 'hola!!', [ + 'time' => $time + (2 * 3600), + ]); +}, $zip_args); |