From eca42d118e439dc0f3796650e8a68992d513f8ee Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 3 Sep 2018 07:12:40 -0400 Subject: add examples/{10,11,12,13}*php, add examples/*zip to .gitignore --- .gitignore | 1 + examples/01-simple.php | 3 ++- examples/10-archive_comment.php | 20 ++++++++++++++++++++ examples/11-add_file_comment.php | 23 +++++++++++++++++++++++ examples/12-add_file_methods.php | 32 ++++++++++++++++++++++++++++++++ examples/13-add_file_times.php | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 examples/10-archive_comment.php create mode 100644 examples/11-add_file_comment.php create mode 100644 examples/12-add_file_methods.php create mode 100644 examples/13-add_file_times.php diff --git a/.gitignore b/.gitignore index a350c2c..21d6443 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ +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 @@ + 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 @@ + 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 @@ + 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); -- cgit v1.2.3