Skip to content

Commit

Permalink
Remove PHP 7 compatibility (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen authored Nov 28, 2022
1 parent 49a6f58 commit 8df0a40
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/part_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["7.4", "8.0", "8.1"]
php: ["8.0", "8.1"]
os: [ubuntu-latest]
experimental: [false]
include:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"symfony/polyfill-mbstring": "^1.0",
"psr/http-message": "^1.0",
"myclabs/php-enum": "^1.5"
Expand Down
60 changes: 8 additions & 52 deletions src/DeflateStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,24 @@

namespace ZipStream;

/**
* @deprecated
*/
class DeflateStream extends Stream
{
protected $filter;

/**
* @var Option\File
*/
protected $options;

/**
* Rewind stream
*
* @return void
*/
public function rewind(): void
public function __construct($stream)
{
// deflate filter needs to be removed before rewind
if ($this->filter) {
$this->removeDeflateFilter();
$this->seek(0);
$this->addDeflateFilter($this->options);
} else {
rewind($this->stream);
}
parent::__construct($stream);
trigger_error('Class ' . __CLASS__ . ' is deprecated, delation will be handled internally instead', E_USER_DEPRECATED);
}

/**
* Remove the deflate filter
*
* @return void
*/
public function removeDeflateFilter(): void
{
if (!$this->filter) {
return;
}
stream_filter_remove($this->filter);
$this->filter = null;
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
}

/**
* Add a deflate filter
*
* @param Option\File $options
* @return void
*/
public function addDeflateFilter(Option\File $options): void
{
$this->options = $options;
// parameter 4 for stream_filter_append expects array
// so we convert the option object in an array
$optionsArr = [
'comment' => $options->getComment(),
'method' => $options->getMethod(),
'deflateLevel' => $options->getDeflateLevel(),
'time' => $options->getTime(),
];
$this->filter = stream_filter_append(
$this->stream,
'zlib.deflate',
STREAM_FILTER_READ,
$optionsArr
);
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);
}
}
15 changes: 1 addition & 14 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function processPath(string $path): void
} else {
$this->method = $this->zip->opt->getLargeFileMethod();

$stream = new DeflateStream(fopen($path, 'rb'));
$stream = new Stream(fopen($path, 'rb'));
$this->processStream($stream);
$stream->close();
}
Expand Down Expand Up @@ -463,19 +463,6 @@ protected function processStreamWithComputedHeader(StreamInterface $stream): voi
$this->readStream($stream, self::COMPUTE);
$stream->rewind();

// incremental compression with deflate_add
// makes this second read unnecessary
// but it is only available from PHP 7.0
if (!$this->deflate && $stream instanceof DeflateStream && $this->method->equals(Method::DEFLATE())) {
$stream->addDeflateFilter($this->opt);
$this->zlen = new Bigint();
while (!$stream->eof()) {
$data = $stream->read(self::CHUNKED_READ_BLOCK_SIZE);
$this->zlen = $this->zlen->add(Bigint::init(strlen($data)));
}
$stream->rewind();
}

$this->addFileHeader();
$this->readStream($stream, self::SEND);
$this->addFileFooter();
Expand Down
2 changes: 1 addition & 1 deletion src/ZipStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function addFileFromStream(string $name, $stream, ?FileOptions $options =
$options->defaultTo($this->opt);

$file = new File($this, $name, $options);
$file->processStream(new DeflateStream($stream));
$file->processStream(new Stream($stream));
}

/**
Expand Down

0 comments on commit 8df0a40

Please sign in to comment.