aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-02 18:56:52 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 09:54:43 -0400
commitac1ddfe5a3b3c97cfab1ae375f201f3f2d241e19 (patch)
treec0eee8674670544d09929ac57ec70c4ba7869206 /src
parentb28f3f09bd0fb28dc48af8d327921b7c02ceb088 (diff)
downloadzipstream-php-ac1ddfe5a3b3c97cfab1ae375f201f3f2d241e19.tar.bz2
zipstream-php-ac1ddfe5a3b3c97cfab1ae375f201f3f2d241e19.zip
add UnknownMethodError
Diffstat (limited to 'src')
-rw-r--r--src/ZipStream.php28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/ZipStream.php b/src/ZipStream.php
index b545bab..e205226 100644
--- a/src/ZipStream.php
+++ b/src/ZipStream.php
@@ -41,7 +41,17 @@ class Error extends \Exception { };
/**
* Deflate context error.
*/
-class DeflateError extends Error { };
+final class DeflateError extends Error { };
+
+final class UnknownMethodError extends Error {
+ /** @var int Unknown compression method. */
+ public $method;
+
+ public function __construct(int $method) {
+ $this->method = $method;
+ parent::__construct('unknown compression method');
+ }
+};
/**
* File related error.
@@ -769,7 +779,8 @@ final class Entry {
} else if ($this->method == Methods::STORE) {
$this->filter = new StoreFilter($this->output);
} else {
- throw new Error('invalid compression method');
+ $this->state = self::ENTRY_STATE_ERROR;
+ throw new UnknownMethodError($this->method);
}
# sanity check path
@@ -1565,11 +1576,18 @@ final class ZipStream {
*/
private function get_entry_method(array &$args) : int {
if (isset($args['method'])) {
- return $args['method'];
+ $r = $args['method'];
} else if (isset($this->args['method'])) {
- return $this->args['method'];
+ $r = $this->args['method'];
} else {
- return Methods::DEFLATE;
+ # fall back to default method
+ $r = Methods::DEFLATE;
+ }
+
+ if ($r != Methods::DEFLATE && $r != Methods::STORE) {
+ throw new UnknownMethodError($r);
}
+
+ return $r;
}
};