diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml
index 497600ea715..d797e7970e7 100644
--- a/lib/thirdpartylibs.xml
+++ b/lib/thirdpartylibs.xml
@@ -585,7 +585,7 @@ All rights reserved.
zipstream
ZipStream-PHP
PHP ZIP Streaming Library
- 2.1.0
+ 2.2.0
MIT
https://github.com/maennchen/ZipStream-PHP
diff --git a/lib/zipstream/src/Bigint.php b/lib/zipstream/src/Bigint.php
index 52ccfd2ea48..ff84d0d54ab 100644
--- a/lib/zipstream/src/Bigint.php
+++ b/lib/zipstream/src/Bigint.php
@@ -108,6 +108,7 @@ class Bigint
/**
* Check if is over 32
*
+ * @psalm-suppress ArgumentTypeCoercion
* @param bool $force
* @return bool
*/
diff --git a/lib/zipstream/src/File.php b/lib/zipstream/src/File.php
index 2200a366be8..6ca1fe7112f 100644
--- a/lib/zipstream/src/File.php
+++ b/lib/zipstream/src/File.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ZipStream;
use Psr\Http\Message\StreamInterface;
+use RuntimeException;
use ZipStream\Exception\EncodingException;
use ZipStream\Exception\FileNotFoundException;
use ZipStream\Exception\FileNotReadableException;
@@ -75,8 +76,9 @@ class File
* @var resource
*/
private $deflate;
+
/**
- * @var resource
+ * @var \HashContext
*/
private $hash;
@@ -291,6 +293,13 @@ class File
$this->version = Version::ZIP64();
}
+ if ($this->bits & self::BIT_EFS_UTF8) {
+ // Put the tricky entry to
+ // force Linux unzip to lookup EFS flag.
+ $fields[] = ['v', 0x5653]; // Choose 'ZS' for proprietary usage
+ $fields[] = ['v', 0x0000]; // zero length
+ }
+
return ZipStream::packFields($fields);
}
@@ -366,7 +375,8 @@ class File
protected function deflateInit(): void
{
- $this->hash = hash_init(self::HASH_ALGORITHM);
+ $hash = hash_init(self::HASH_ALGORITHM);
+ $this->hash = $hash;
if ($this->method->equals(Method::DEFLATE())) {
$this->deflate = deflate_init(
ZLIB_ENCODING_RAW,
diff --git a/lib/zipstream/src/Option/Archive.php b/lib/zipstream/src/Option/Archive.php
index b6b95cce54c..21d14d8c53c 100644
--- a/lib/zipstream/src/Option/Archive.php
+++ b/lib/zipstream/src/Option/Archive.php
@@ -3,6 +3,8 @@ declare(strict_types=1);
namespace ZipStream\Option;
+use Psr\Http\Message\StreamInterface;
+
final class Archive
{
const DEFAULT_DEFLATE_LEVEL = 6;
@@ -104,7 +106,7 @@ final class Archive
private $deflateLevel = 6;
/**
- * @var resource
+ * @var StreamInterface|resource
*/
private $outputStream;
@@ -228,7 +230,7 @@ final class Archive
}
/**
- * @return resource
+ * @return StreamInterface|resource
*/
public function getOutputStream()
{
@@ -236,7 +238,7 @@ final class Archive
}
/**
- * @param resource $outputStream
+ * @param StreamInterface|resource $outputStream
*/
public function setOutputStream($outputStream): void
{
diff --git a/lib/zipstream/src/Option/File.php b/lib/zipstream/src/Option/File.php
index 7fd29ea55c5..05ff7b5ee52 100644
--- a/lib/zipstream/src/Option/File.php
+++ b/lib/zipstream/src/Option/File.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ZipStream\Option;
use DateTime;
+use DateTimeInterface;
final class File
{
@@ -20,7 +21,7 @@ final class File
*/
private $deflateLevel;
/**
- * @var DateTime
+ * @var DateTimeInterface
*/
private $time;
/**
@@ -83,17 +84,17 @@ final class File
}
/**
- * @return DateTime
+ * @return DateTimeInterface
*/
- public function getTime(): DateTime
+ public function getTime(): DateTimeInterface
{
return $this->time;
}
/**
- * @param DateTime $time
+ * @param DateTimeInterface $time
*/
- public function setTime(DateTime $time): void
+ public function setTime(DateTimeInterface $time): void
{
$this->time = $time;
}
diff --git a/lib/zipstream/src/Stream.php b/lib/zipstream/src/Stream.php
index bf410a3425f..686c3a6b08f 100644
--- a/lib/zipstream/src/Stream.php
+++ b/lib/zipstream/src/Stream.php
@@ -67,7 +67,7 @@ class Stream implements StreamInterface
{
try {
$this->seek(0);
- } catch (\RuntimeException $e) {}
+ } catch (RuntimeException $e) {}
return (string) stream_get_contents($this->stream);
}
@@ -81,7 +81,7 @@ class Stream implements StreamInterface
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
* offset bytes SEEK_CUR: Set position to current location plus offset
* SEEK_END: Set position to end-of-stream plus offset.
- * @throws \RuntimeException on failure.
+ * @throws RuntimeException on failure.
*/
public function seek($offset, $whence = SEEK_SET): void
{
@@ -136,7 +136,7 @@ class Stream implements StreamInterface
* Returns the current position of the file read/write pointer
*
* @return int Position of the file pointer
- * @throws \RuntimeException on error.
+ * @throws RuntimeException on error.
*/
public function tell(): int
{
@@ -165,7 +165,7 @@ class Stream implements StreamInterface
*
* @see seek()
* @link http://www.php.net/manual/en/function.fseek.php
- * @throws \RuntimeException on failure.
+ * @throws RuntimeException on failure.
*/
public function rewind(): void
{
@@ -177,7 +177,7 @@ class Stream implements StreamInterface
*
* @param string $string The string that is to be written.
* @return int Returns the number of bytes written to the stream.
- * @throws \RuntimeException on failure.
+ * @throws RuntimeException on failure.
*/
public function write($string): int
{
@@ -197,7 +197,11 @@ class Stream implements StreamInterface
*/
public function isWritable(): bool
{
- return preg_match('/[waxc+]/', $this->getMetadata('mode')) === 1;
+ $mode = $this->getMetadata('mode');
+ if (!is_string($mode)) {
+ throw new RuntimeException('Could not get stream mode from metadata!');
+ }
+ return preg_match('/[waxc+]/', $mode) === 1;
}
/**
@@ -229,7 +233,11 @@ class Stream implements StreamInterface
*/
public function isReadable(): bool
{
- return preg_match('/[r+]/', $this->getMetadata('mode')) === 1;
+ $mode = $this->getMetadata('mode');
+ if (!is_string($mode)) {
+ throw new RuntimeException('Could not get stream mode from metadata!');
+ }
+ return preg_match('/[r+]/', $mode) === 1;
}
/**
diff --git a/lib/zipstream/src/ZipStream.php b/lib/zipstream/src/ZipStream.php
index e83038cf016..d281d259fa0 100644
--- a/lib/zipstream/src/ZipStream.php
+++ b/lib/zipstream/src/ZipStream.php
@@ -312,12 +312,9 @@ class ZipStream
*
* Examples:
*
- * // create a temporary file stream and write text to it
- * $fp = tmpfile();
- * fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
- *
+ * $stream = $response->getBody();
* // add a file named 'streamfile.txt' from the content of the stream
- * $x->addFileFromPsr7Stream('streamfile.txt', $fp);
+ * $x->addFileFromPsr7Stream('streamfile.txt', $stream);
*
* @return void
*/
@@ -459,7 +456,13 @@ class ZipStream
}
$this->need_headers = false;
- fwrite($this->opt->getOutputStream(), $str);
+ $outputStream = $this->opt->getOutputStream();
+
+ if ($outputStream instanceof StreamInterface) {
+ $outputStream->write($str);
+ } else {
+ fwrite($outputStream, $str);
+ }
if ($this->opt->isFlushOutput()) {
// flush output buffer if it is on and flushable