From 2837e2eb1b8d868a5b71bc038a086e28b54d039f Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 25 Aug 2018 14:10:14 -0400 Subject: initial comimt --- src/ZipStream.php | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/ZipStream.php (limited to 'src/ZipStream.php') 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 @@ + '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"); + } + } + +}; -- cgit v1.2.3