From b520b6459d7b5a3dfb31c1b3febf02887bb07505 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 2 Sep 2018 13:16:16 -0400 Subject: add examples --- examples/04-add.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/04-add.php (limited to 'examples/04-add.php') diff --git a/examples/04-add.php b/examples/04-add.php new file mode 100644 index 0000000..3843086 --- /dev/null +++ b/examples/04-add.php @@ -0,0 +1,44 @@ + '01-simple.php', + 'summary-04.txt' => '04-add.php', +]; + +# create the output archive named "example.zip" +$zip = new ZipStream('example.zip'); + +foreach ($files as $dst_path => $src_path) { + $zip->add($dst_path, function(&$e) use ($src_path) { + # build absolute path to source file + $abs_src_path = __DIR__ . "/$src_path"; + + # read file contents and get md5 hash + $data = file_get_contents($abs_src_path); + + # build arguments + $args = [ + 'source' => $src_path, + 'md5' => md5($data), + 'sha1' => sha1($data), + ]; + + # write lines to output archive + foreach ($args as $key => $val) { + # build line + $line = "$key: $val\n"; + + # write line to output file + $e->write($line); + } + }); +} + +# finalize the output stream +$zip->close(); -- cgit v1.2.3