aboutsummaryrefslogtreecommitdiff
path: root/src/ZipStream.php
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-08-25 14:10:14 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 09:54:30 -0400
commit2837e2eb1b8d868a5b71bc038a086e28b54d039f (patch)
treee75bbbfcf51f1f6172c3e9b509372329343c0767 /src/ZipStream.php
parent7134bcf24c9e6a1b4c35f7c9ed5f3326e3be9e40 (diff)
downloadzipstream-php-2837e2eb1b8d868a5b71bc038a086e28b54d039f.tar.bz2
zipstream-php-2837e2eb1b8d868a5b71bc038a086e28b54d039f.zip
initial comimt
Diffstat (limited to 'src/ZipStream.php')
-rw-r--r--src/ZipStream.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/ZipStream.php b/src/ZipStream.php
new file mode 100644
index 0000000..b6953ef
--- /dev/null
+++ b/src/ZipStream.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace Pablotron\ZipStream;
+
+final class ZipStream {
+ const VERSION = "0.2.0";
+
+ public $zip_name;
+ private $args;
+ private $entries = array();
+
+ static $DEFAULT_ARCHIVE_OPTIONS = [
+ 'method' => 'deflate'
+ 'comment' => '',
+ 'header' => true,
+ ];
+
+ static $DEFAULT_FILE_OPTIONS = [
+ 'comment' => '',
+ ];
+
+ public function __construct(
+ string $zip_name,
+ array $args = array()
+ ) {
+ $this->zip_name = $zip_name;
+ $this->args = array_merge(
+ self::$DEFAULT_ARCHIVE_OPTIONS,
+ $args
+ );
+ }
+
+ public function add_text(
+ string $dst_path,
+ array $args = array()
+ ) {
+ $this->check_path($dst_path);
+ $this->entries[] = pack('VvvvvvVVVvv'
+ }
+
+ public function add_path(
+ string $dst_path,
+ string $src_path = null,
+ array $args = array()
+ )
+
+ public function add_stream(
+ string $dst_path,
+ $src_stream,
+ array $args = array()
+ )
+
+ public function finish() {
+ }
+
+ public static function send($name, array $args, function $cb) {
+ $zip = new self($name, $args);
+ $cb($zip);
+ $zip->finish();
+ }
+
+ private function check_path(string $path) {
+ # make sure path is non-null
+ if (!$path) {
+ throw new Exception("null path");
+ }
+
+ # check for empty path
+ if (!strlen($path)) {
+ throw new Exception("empty path");
+ }
+
+ # check for long path
+ if (strlen($path) > 65535) {
+ throw new Exception("path too long");
+ }
+
+ # check for leading slash
+ if (!$path[0] == '/') {
+ throw new Exception("path contains leading slash");
+ }
+
+ # check for trailing slash
+ if (preg_match('/\\$/', $path)) {
+ throw new Exception("path contains trailing slash");
+ }
+
+ # check for double slashes
+ if (preg_match('/\/\//', $path))
+ throw new Exception("path contains double slashes");
+ }
+
+ # check for double dots
+ if (preg_match('/\.\./', $path))
+ throw new Exception("relative path");
+ }
+ }
+
+};