package and depencies
This commit is contained in:
22
vendor/maennchen/zipstream-php/.editorconfig
vendored
Normal file
22
vendor/maennchen/zipstream-php/.editorconfig
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
|
||||
[*.{yml,md,xml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{rst,php}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[composer.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[composer.lock]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
@@ -1 +0,0 @@
|
||||
open_collective: zipstream
|
||||
@@ -1,12 +0,0 @@
|
||||
# Description of the problem
|
||||
|
||||
Please be very descriptive and include as much details as possible.
|
||||
|
||||
# Example code
|
||||
|
||||
# Informations
|
||||
|
||||
* ZipStream-PHP version:
|
||||
* PHP version:
|
||||
|
||||
Please include any supplemental information you deem relevant to this issue.
|
||||
6
vendor/maennchen/zipstream-php/.gitignore
vendored
6
vendor/maennchen/zipstream-php/.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
clover.xml
|
||||
composer.lock
|
||||
coverage.clover
|
||||
.idea
|
||||
phpunit.xml
|
||||
vendor
|
||||
4
vendor/maennchen/zipstream-php/.phive/phars.xml
vendored
Normal file
4
vendor/maennchen/zipstream-php/.phive/phars.xml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phive xmlns="https://phar.io/phive">
|
||||
<phar name="phpdocumentor" version="^3.3.1" installed="3.3.1" location="./tools/phpdocumentor" copy="false"/>
|
||||
</phive>
|
||||
71
vendor/maennchen/zipstream-php/.php-cs-fixer.dist.php
vendored
Normal file
71
vendor/maennchen/zipstream-php/.php-cs-fixer.dist.php
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* PHP-CS-Fixer config for ZipStream-PHP
|
||||
* @author Nicolas CARPi <nico-git@deltablot.email>
|
||||
* @copyright 2022 Nicolas CARPi
|
||||
* @see https://github.com/maennchen/ZipStream-PHP
|
||||
* @license MIT
|
||||
* @package maennchen/ZipStream-PHP
|
||||
*/
|
||||
|
||||
use PhpCsFixer\Config;
|
||||
use PhpCsFixer\Finder;
|
||||
|
||||
$finder = Finder::create()
|
||||
->exclude('.github')
|
||||
->exclude('.phpdoc')
|
||||
->exclude('docs')
|
||||
->exclude('tools')
|
||||
->exclude('vendor')
|
||||
->in(__DIR__);
|
||||
|
||||
$config = new Config();
|
||||
return $config->setRules([
|
||||
'@PER' => true,
|
||||
'@PER:risky' => true,
|
||||
'@PHP81Migration' => true,
|
||||
'@PHPUnit84Migration:risky' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'class_attributes_separation' => true,
|
||||
'declare_strict_types' => true,
|
||||
'dir_constant' => true,
|
||||
'is_null' => true,
|
||||
'no_homoglyph_names' => true,
|
||||
'no_null_property_initialization' => true,
|
||||
'no_php4_constructor' => true,
|
||||
'no_unused_imports' => true,
|
||||
'no_useless_else' => true,
|
||||
'non_printable_character' => true,
|
||||
'ordered_imports' => true,
|
||||
'ordered_class_elements' => true,
|
||||
'php_unit_construct' => true,
|
||||
'pow_to_exponentiation' => true,
|
||||
'psr_autoloading' => true,
|
||||
'random_api_migration' => true,
|
||||
'return_assignment' => true,
|
||||
'self_accessor' => true,
|
||||
'semicolon_after_instruction' => true,
|
||||
'short_scalar_cast' => true,
|
||||
'simplified_null_return' => true,
|
||||
'single_blank_line_before_namespace' => true,
|
||||
'single_class_element_per_statement' => true,
|
||||
'single_line_comment_style' => true,
|
||||
'single_quote' => true,
|
||||
'space_after_semicolon' => true,
|
||||
'standardize_not_equals' => true,
|
||||
'strict_param' => true,
|
||||
'ternary_operator_spaces' => true,
|
||||
'trailing_comma_in_multiline' => true,
|
||||
'trim_array_spaces' => true,
|
||||
'unary_operator_spaces' => true,
|
||||
'global_namespace_import' => [
|
||||
'import_classes' => true,
|
||||
'import_functions' => true,
|
||||
'import_constants' => true,
|
||||
],
|
||||
])
|
||||
->setFinder($finder)
|
||||
->setRiskyAllowed(true);
|
||||
15
vendor/maennchen/zipstream-php/.phpdoc/template/base.html.twig
vendored
Normal file
15
vendor/maennchen/zipstream-php/.phpdoc/template/base.html.twig
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{% extends 'layout.html.twig' %}
|
||||
|
||||
{% set topMenu = {
|
||||
"menu": [
|
||||
{ "name": "Guides", "url": "https://maennchen.dev/ZipStream-PHP/guide/index.html"},
|
||||
{ "name": "API", "url": "https://maennchen.dev/ZipStream-PHP/classes/ZipStream-ZipStream.html"},
|
||||
{ "name": "Issues", "url": "https://github.com/maennchen/ZipStream-PHP/issues"},
|
||||
],
|
||||
"social": [
|
||||
{ "iconClass": "fab fa-github", "url": "https://github.com/maennchen/ZipStream-PHP"},
|
||||
{ "iconClass": "fas fa-envelope-open-text", "url": "https://github.com/maennchen/ZipStream-PHP/discussions"},
|
||||
{ "iconClass": "fas fa-money-bill", "url": "https://opencollective.com/zipstream"},
|
||||
]
|
||||
}
|
||||
%}
|
||||
1
vendor/maennchen/zipstream-php/.tool-versions
vendored
Normal file
1
vendor/maennchen/zipstream-php/.tool-versions
vendored
Normal file
@@ -0,0 +1 @@
|
||||
php 8.2.0
|
||||
12
vendor/maennchen/zipstream-php/.travis.yml
vendored
12
vendor/maennchen/zipstream-php/.travis.yml
vendored
@@ -1,12 +0,0 @@
|
||||
language: php
|
||||
dist: trusty
|
||||
sudo: false
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
install: composer install
|
||||
script: ./vendor/bin/phpunit --coverage-clover=coverage.clover
|
||||
after_script:
|
||||
- wget https://scrutinizer-ci.com/ocular.phar
|
||||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
|
||||
51
vendor/maennchen/zipstream-php/CHANGELOG.md
vendored
51
vendor/maennchen/zipstream-php/CHANGELOG.md
vendored
@@ -1,51 +0,0 @@
|
||||
# CHANGELOG for ZipStream-PHP
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.1.0] - 2020-06-01
|
||||
### Changed
|
||||
- Don't execute ob_flush() when output buffering is not enabled (#152)
|
||||
- Fix inconsistent return type on 32-bit systems (#149) Fix #144
|
||||
- Use mbstring polyfill (#151)
|
||||
- Promote 7zip usage over unzip to avoid UTF-8 issues (#147)
|
||||
|
||||
## [2.0.0] - 2020-02-22
|
||||
### Breaking change
|
||||
- Only the self opened streams will be closed (#139)
|
||||
If you were relying on ZipStream to close streams that the library didn't open,
|
||||
you'll need to close them yourself now.
|
||||
|
||||
### Changed
|
||||
- Minor change to data descriptor (#136)
|
||||
|
||||
## [1.2.0] - 2019-07-11
|
||||
|
||||
### Added
|
||||
- Option to flush output buffer after every write (#122)
|
||||
|
||||
## [1.1.0] - 2019-04-30
|
||||
|
||||
### Fixed
|
||||
- Honor last-modified timestamps set via `ZipStream\Option\File::setTime()` (#106)
|
||||
- Documentation regarding output of HTTP headers
|
||||
- Test warnings with PHPUnit (#109)
|
||||
|
||||
### Added
|
||||
- Test for FileNotReadableException (#114)
|
||||
- Size attribute to File options (#113)
|
||||
- Tests on PHP 7.3 (#108)
|
||||
|
||||
## [1.0.0] - 2019-04-17
|
||||
|
||||
### Breaking changes
|
||||
- Mininum PHP version is now 7.1
|
||||
- Options are now passed to the ZipStream object via the Option\Archive object. See the wiki for available options and code examples
|
||||
|
||||
### Added
|
||||
- Add large file support with Zip64 headers
|
||||
|
||||
### Changed
|
||||
- Major refactoring and code cleanup
|
||||
25
vendor/maennchen/zipstream-php/CONTRIBUTING.md
vendored
25
vendor/maennchen/zipstream-php/CONTRIBUTING.md
vendored
@@ -1,25 +0,0 @@
|
||||
# ZipStream Readme for Contributors
|
||||
## Code styling
|
||||
### Indention
|
||||
For spaces are used to indent code. The convention is [K&R](http://en.wikipedia.org/wiki/Indent_style#K&R)
|
||||
|
||||
### Comments
|
||||
Double Slashes are used for an one line comment.
|
||||
|
||||
Classes, Variables, Methods etc:
|
||||
|
||||
```php
|
||||
/**
|
||||
* My comment
|
||||
*
|
||||
* @myanotation like @param etc.
|
||||
*/
|
||||
```
|
||||
|
||||
## Pull requests
|
||||
Feel free to submit pull requests.
|
||||
|
||||
## Testing
|
||||
For every new feature please write a new PHPUnit test.
|
||||
|
||||
Before every commit execute `./vendor/bin/phpunit` to check if your changes wrecked something:
|
||||
61
vendor/maennchen/zipstream-php/README.md
vendored
61
vendor/maennchen/zipstream-php/README.md
vendored
@@ -1,12 +1,17 @@
|
||||
# ZipStream-PHP
|
||||
|
||||
[](https://travis-ci.org/maennchen/ZipStream-PHP)
|
||||
[](https://scrutinizer-ci.com/g/maennchen/ZipStream-PHP/)
|
||||
[](https://scrutinizer-ci.com/g/maennchen/ZipStream-PHP/)
|
||||
[](https://github.com/maennchen/ZipStream-PHP/actions/workflows/branch_main.yml)
|
||||
[](https://coveralls.io/github/maennchen/ZipStream-PHP?branch=main)
|
||||
[](https://packagist.org/packages/maennchen/zipstream-php)
|
||||
[](https://packagist.org/packages/maennchen/zipstream-php)
|
||||
[](https://opencollective.com/zipstream) [](LICENSE)
|
||||
|
||||
## Unstable Branch
|
||||
|
||||
The `main` branch is not stable. Please see the
|
||||
[releases](https://github.com/maennchen/ZipStream-PHP/releases) for a stable
|
||||
version.
|
||||
|
||||
## Overview
|
||||
|
||||
A fast and simple streaming zip file downloader for PHP. Using this library will save you from having to write the Zip to disk. You can directly send it to the user, which is much faster. It can work with S3 buckets or any PSR7 Stream.
|
||||
@@ -21,7 +26,10 @@ Simply add a dependency on maennchen/zipstream-php to your project's composer.js
|
||||
composer require maennchen/zipstream-php
|
||||
```
|
||||
|
||||
## Usage and options
|
||||
## Usage
|
||||
|
||||
For detailed instructions, please check the
|
||||
[Documentation](https://maennchen.dev/ZipStream-PHP/).
|
||||
|
||||
Here's a simple example:
|
||||
|
||||
@@ -42,39 +50,20 @@ $zip->addFile('hello.txt', 'This is the contents of hello.txt');
|
||||
// add a file named 'some_image.jpg' from a local file 'path/to/image.jpg'
|
||||
$zip->addFileFromPath('some_image.jpg', 'path/to/image.jpg');
|
||||
|
||||
// add a file named 'goodbye.txt' from an open stream resource
|
||||
$fp = tmpfile();
|
||||
fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
|
||||
rewind($fp);
|
||||
$zip->addFileFromStream('goodbye.txt', $fp);
|
||||
fclose($fp);
|
||||
|
||||
// finish the zip stream
|
||||
$zip->finish();
|
||||
```
|
||||
|
||||
You can also add comments, modify file timestamps, and customize (or
|
||||
disable) the HTTP headers. It is also possible to specify the storage method when adding files,
|
||||
the current default storage method is 'deflate' i.e files are stored with Compression mode 0x08.
|
||||
|
||||
See the [Wiki](https://github.com/maennchen/ZipStream-PHP/wiki) for details.
|
||||
|
||||
## Known issue
|
||||
|
||||
The native Mac OS archive extraction tool might not open archives in some conditions. A workaround is to disable the Zip64 feature with the option `$opt->setEnableZip64(false)`. This limits the archive to 4 Gb and 64k files but will allow Mac OS users to open them without issue. See #116.
|
||||
|
||||
The linux `unzip` utility might not handle properly unicode characters. It is recommended to extract with another tool like [7-zip](https://www.7-zip.org/). See #146.
|
||||
|
||||
## Upgrade to version 2.0.0
|
||||
|
||||
* Only the self opened streams will be closed (#139)
|
||||
If you were relying on ZipStream to close streams that the library didn't open,
|
||||
you'll need to close them yourself now.
|
||||
- Only the self opened streams will be closed (#139)
|
||||
If you were relying on ZipStream to close streams that the library didn't open,
|
||||
you'll need to close them yourself now.
|
||||
|
||||
## Upgrade to version 1.0.0
|
||||
|
||||
* All options parameters to all function have been moved from an `array` to structured option objects. See [the wiki](https://github.com/maennchen/ZipStream-PHP/wiki/Available-options) for examples.
|
||||
* The whole library has been refactored. The minimal PHP requirement has been raised to PHP 7.1.
|
||||
- All options parameters to all function have been moved from an `array` to structured option objects. See [the wiki](https://github.com/maennchen/ZipStream-PHP/wiki/Available-options) for examples.
|
||||
- The whole library has been refactored. The minimal PHP requirement has been raised to PHP 7.1.
|
||||
|
||||
## Usage with Symfony and S3
|
||||
|
||||
@@ -82,21 +71,23 @@ You can find example code on [the wiki](https://github.com/maennchen/ZipStream-P
|
||||
|
||||
## Contributing
|
||||
|
||||
ZipStream-PHP is a collaborative project. Please take a look at the [CONTRIBUTING.md](CONTRIBUTING.md) file.
|
||||
ZipStream-PHP is a collaborative project. Please take a look at the
|
||||
[.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) file.
|
||||
|
||||
## About the Authors
|
||||
|
||||
* Paul Duncan <pabs@pablotron.org> - https://pablotron.org/
|
||||
* Jonatan Männchen <jonatan@maennchen.ch> - https://maennchen.dev
|
||||
* Jesse G. Donat <donatj@gmail.com> - https://donatstudios.com
|
||||
* Nicolas CARPi <nico-git@deltablot.email> - https://www.deltablot.com
|
||||
* Nik Barham <nik@brokencube.co.uk> - https://www.brokencube.co.uk
|
||||
- Paul Duncan <pabs@pablotron.org> - https://pablotron.org/
|
||||
- Jonatan Männchen <jonatan@maennchen.ch> - https://maennchen.dev
|
||||
- Jesse G. Donat <donatj@gmail.com> - https://donatstudios.com
|
||||
- Nicolas CARPi <nico-git@deltablot.email> - https://www.deltablot.com
|
||||
- Nik Barham <nik@brokencube.co.uk> - https://www.brokencube.co.uk
|
||||
|
||||
## Contributors
|
||||
|
||||
### Code Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||
This project exists thanks to all the people who contribute.
|
||||
[[Contribute](.github/CONTRIBUTING.md)].
|
||||
<a href="https://github.com/maennchen/ZipStream-PHP/graphs/contributors"><img src="https://opencollective.com/zipstream/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
### Financial Contributors
|
||||
|
||||
45
vendor/maennchen/zipstream-php/composer.json
vendored
45
vendor/maennchen/zipstream-php/composer.json
vendored
@@ -22,20 +22,55 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">= 7.1",
|
||||
"symfony/polyfill-mbstring": "^1.0",
|
||||
"php": "^8.0",
|
||||
"ext-mbstring": "*",
|
||||
"psr/http-message": "^1.0",
|
||||
"myclabs/php-enum": "^1.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">= 7.5",
|
||||
"guzzlehttp/guzzle": ">= 6.3",
|
||||
"phpunit/phpunit": "^8.5.8 || ^9.4.2",
|
||||
"guzzlehttp/guzzle": "^6.5.3 || ^7.2.0",
|
||||
"ext-zip": "*",
|
||||
"mikey179/vfsstream": "^1.6"
|
||||
"mikey179/vfsstream": "^1.6",
|
||||
"vimeo/psalm": "^5.0",
|
||||
"php-coveralls/php-coveralls": "^2.4",
|
||||
"friendsofphp/php-cs-fixer": "^3.9"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix",
|
||||
"test": "composer run test:unit && composer run test:formatted && composer run test:lint",
|
||||
"test:unit": "phpunit --coverage-clover=coverage.clover.xml --coverage-html cov",
|
||||
"test:formatted": "composer run format -- --dry-run --stop-on-violation --using-cache=no",
|
||||
"test:lint": "psalm --stats --show-info --find-unused-psalm-suppress",
|
||||
"coverage:report": "php-coveralls --coverage_clover=coverage.clover.xml --json_path=coveralls-upload.json --insecure",
|
||||
"install:tools": "phive install --trust-gpg-keys 0x67F861C3D889C656",
|
||||
"docs:generate": "tools/phpdocumentor --sourcecode"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ZipStream\\": "src/"
|
||||
}
|
||||
},
|
||||
"archive": {
|
||||
"exclude": [
|
||||
"/composer.lock",
|
||||
"/docs",
|
||||
"/.gitattributes",
|
||||
"/.github",
|
||||
"/.gitignore",
|
||||
"/guides",
|
||||
"/.phive",
|
||||
"/.php-cs-fixer.cache",
|
||||
"/.php-cs-fixer.dist.php",
|
||||
"/.phpdoc",
|
||||
"/phpdoc.dist.xml",
|
||||
"/.phpunit.result.cache",
|
||||
"/phpunit.xml.dist",
|
||||
"/psalm.xml",
|
||||
"/test",
|
||||
"/tools",
|
||||
"/.tool-versions",
|
||||
"/vendor"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
79
vendor/maennchen/zipstream-php/guides/ContentLength.rst
vendored
Normal file
79
vendor/maennchen/zipstream-php/guides/ContentLength.rst
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
Adding Content-Length header
|
||||
=============
|
||||
|
||||
Adding a ``Content-Length`` header for ``ZipStream`` is not trivial since the
|
||||
size is not known beforehand.
|
||||
|
||||
The following workaround adds an approximated header:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
class Zip
|
||||
{
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
private $files = [];
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function addFile($name, $data)
|
||||
{
|
||||
$this->files[] = ['type' => 'addFile', 'name' => $name, 'data' => $data];
|
||||
}
|
||||
|
||||
public function addFileFromPath($name, $path)
|
||||
{
|
||||
$this->files[] = ['type' => 'addFileFromPath', 'name' => $name, 'path' => $path];
|
||||
}
|
||||
|
||||
public function getEstimate()
|
||||
{
|
||||
$estimate = 22;
|
||||
foreach ($this->files as $file) {
|
||||
$estimate += 76 + 2 * strlen($file['name']);
|
||||
if ($file['type'] === 'addFile') {
|
||||
$estimate += strlen($file['data']);
|
||||
}
|
||||
if ($file['type'] === 'addFileFromPath') {
|
||||
$estimate += filesize($file['path']);
|
||||
}
|
||||
}
|
||||
return $estimate;
|
||||
}
|
||||
|
||||
public function finish()
|
||||
{
|
||||
header('Content-Length: ' . $this->getEstimate());
|
||||
$options = new \ZipStream\Option\Archive();
|
||||
$options->setSendHttpHeaders(true);
|
||||
$options->setEnableZip64(false);
|
||||
$options->setDeflateLevel(-1);
|
||||
$zip = new \ZipStream\ZipStream($this->name, $options);
|
||||
|
||||
$fileOptions = new \ZipStream\Option\File();
|
||||
$fileOptions->setMethod(\ZipStream\Option\Method::STORE());
|
||||
foreach ($this->files as $file) {
|
||||
if ($file['type'] === 'addFile') {
|
||||
$zip->addFile($file['name'], $file['data'], $fileOptions);
|
||||
}
|
||||
if ($file['type'] === 'addFileFromPath') {
|
||||
$zip->addFileFromPath($file['name'], $file['path'], $fileOptions);
|
||||
}
|
||||
}
|
||||
$zip->finish();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
It only works with the following constraints:
|
||||
|
||||
- All file content is known beforehand.
|
||||
- Content Deflation is disabled
|
||||
|
||||
Thanks to
|
||||
`partiellkorrekt <https://github.com/maennchen/ZipStream-PHP/issues/89#issuecomment-1047949274>`_
|
||||
for this workaround.
|
||||
33
vendor/maennchen/zipstream-php/guides/FlySystem.rst
vendored
Normal file
33
vendor/maennchen/zipstream-php/guides/FlySystem.rst
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
Usage with FlySystem
|
||||
===============
|
||||
|
||||
For saving or uploading the generated zip, you can use the
|
||||
`Flysystem <https://flysystem.thephpleague.com>`_ package, and its many
|
||||
adapters.
|
||||
|
||||
For that you will need to provide another stream than the ``php://output``
|
||||
default one, and pass it to Flysystem ``putStream`` method.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// Open Stream only once for read and write since it's a memory stream and
|
||||
// the content is lost when closing the stream / opening another one
|
||||
$tempStream = fopen('php://memory', 'w+');
|
||||
|
||||
// Init Options
|
||||
$zipStreamOptions = new Archive();
|
||||
$zipStreamOptions->setOutputStream($tempStream);
|
||||
|
||||
// Create Zip Archive
|
||||
$zipStream = new ZipStream('test.zip', $zipStreamOptions);
|
||||
$zipStream->addFile('test.txt', 'text');
|
||||
$zipStream->finish();
|
||||
|
||||
// Store File (see Flysystem documentation, and all its framework integration)
|
||||
$adapter = new Local(__DIR__.'/path/to/folder'); // Can be any adapter (AWS, Google, Ftp, etc.)
|
||||
$filesystem = new Filesystem($adapter);
|
||||
|
||||
$filesystem->putStream('test.zip', $tempStream)
|
||||
|
||||
// Close Stream
|
||||
fclose($tempStream);
|
||||
16
vendor/maennchen/zipstream-php/guides/Nginx.rst
vendored
Normal file
16
vendor/maennchen/zipstream-php/guides/Nginx.rst
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
Usage with nginx
|
||||
=============
|
||||
|
||||
If you are using nginx as a webserver, it will try to buffer the response.
|
||||
So you'll want to disable this with a custom header:
|
||||
|
||||
.. code-block:: php
|
||||
header('X-Accel-Buffering: no');
|
||||
# or with the Response class from Symfony
|
||||
$response->headers->set('X-Accel-Buffering', 'no');
|
||||
|
||||
Alternatively, you can tweak the
|
||||
`fastcgi cache parameters <https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffers>`_
|
||||
within nginx config.
|
||||
|
||||
See `original issue <https://github.com/maennchen/ZipStream-PHP/issues/77>`_.
|
||||
61
vendor/maennchen/zipstream-php/guides/Options.rst
vendored
Normal file
61
vendor/maennchen/zipstream-php/guides/Options.rst
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
Available options
|
||||
===============
|
||||
|
||||
Here is the full list of options available to you. You can also have a look at
|
||||
``src/Option/Archive.php`` file.
|
||||
|
||||
First, an instance of ``ZipStream\Option\Archive`` needs to be created, and
|
||||
after that you use setters methods to modify the values.
|
||||
|
||||
.. code-block:: php
|
||||
use ZipStream\ZipStream;
|
||||
use ZipStream\Option\Archive as ArchiveOptions;
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
$opt = new ArchiveOptions();
|
||||
|
||||
// Define output stream (argument is of type resource)
|
||||
$opt->setOutputStream($fd);
|
||||
|
||||
// Set the deflate level (default is 6; use -1 to disable it)
|
||||
$opt->setDeflateLevel(6);
|
||||
|
||||
// Add a comment to the zip file
|
||||
$opt->setComment('This is a comment.');
|
||||
|
||||
// Size, in bytes, of the largest file to try and load into memory (used by addFileFromPath()). Large files may also be compressed differently; see the 'largeFileMethod' option.
|
||||
$opt->setLargeFileSize(30000000);
|
||||
|
||||
// How to handle large files. Legal values are STORE (the default), or DEFLATE. Store sends the file raw and is significantly faster, while DEFLATE compresses the file and is much, much slower. Note that deflate must compress the file twice and is extremely slow.
|
||||
$opt->setLargeFileMethod(ZipStream\Option\Method::STORE());
|
||||
$opt->setLargeFileMethod(ZipStream\Option\Method::DEFLATE());
|
||||
|
||||
// Send http headers (default is false)
|
||||
$opt->setSendHttpHeaders(false);
|
||||
|
||||
// HTTP Content-Disposition. Defaults to 'attachment', where FILENAME is the specified filename. Note that this does nothing if you are not sending HTTP headers.
|
||||
$opt->setContentDisposition('attachment');
|
||||
|
||||
// Set the content type (does nothing if you are not sending HTTP headers)
|
||||
$opt->setContentType('application/x-zip');
|
||||
|
||||
// Set the function called for setting headers. Default is the `header()` of PHP
|
||||
$opt->setHttpHeaderCallback('header');
|
||||
|
||||
// Enable streaming files with single read where general purpose bit 3 indicates local file header contain zero values in crc and size fields, these appear only after file contents in data descriptor block. Default is false. Set to true if your input stream is remote (used with addFileFromStream()).
|
||||
$opt->setZeroHeader(false);
|
||||
|
||||
// Enable reading file stat for determining file size. When a 32-bit system reads file size that is over 2 GB, invalid value appears in file size due to integer overflow. Should be disabled on 32-bit systems with method addFileFromPath if any file may exceed 2 GB. In this case file will be read in blocks and correct size will be determined from content. Default is true.
|
||||
$opt->setStatFiles(true);
|
||||
|
||||
// Enable zip64 extension, allowing very large archives (> 4Gb or file count > 64k)
|
||||
// default is true
|
||||
$opt->setEnableZip64(true);
|
||||
|
||||
// Flush output buffer after every write
|
||||
// default is false
|
||||
$opt->setFlushOutput(true);
|
||||
|
||||
// Now that everything is set you can pass the options to the ZipStream instance
|
||||
$zip = new ZipStream('example.zip', $opt);
|
||||
18
vendor/maennchen/zipstream-php/guides/PSR7Streams.rst
vendored
Normal file
18
vendor/maennchen/zipstream-php/guides/PSR7Streams.rst
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
Usage with PSR 7 Streams
|
||||
===============
|
||||
|
||||
PSR-7 streams are `standardized streams <https://www.php-fig.org/psr/psr-7/>`_.
|
||||
|
||||
ZipStream-PHP supports working with these streams with the function
|
||||
``addFileFromPsr7Stream``.
|
||||
|
||||
For all parameters of the function see the API documentation.
|
||||
|
||||
Example
|
||||
---------------
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$stream = $response->getBody();
|
||||
// add a file named 'streamfile.txt' from the content of the stream
|
||||
$zip->addFileFromPsr7Stream('streamfile.txt', $stream);
|
||||
33
vendor/maennchen/zipstream-php/guides/StreamOutput.rst
vendored
Normal file
33
vendor/maennchen/zipstream-php/guides/StreamOutput.rst
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
Stream Output
|
||||
===============
|
||||
|
||||
Stream to S3 Bucket
|
||||
---------------
|
||||
|
||||
.. code-block:: php
|
||||
use Aws\S3\S3Client;
|
||||
use Aws\Credentials\CredentialProvider;
|
||||
use ZipStream\Option\Archive;
|
||||
use ZipStream\ZipStream;
|
||||
|
||||
$bucket = 'your bucket name';
|
||||
$client = new S3Client([
|
||||
'region' => 'your region',
|
||||
'version' => 'latest',
|
||||
'bucketName' => $bucket,
|
||||
'credentials' => CredentialProvider::defaultProvider(),
|
||||
]);
|
||||
$client->registerStreamWrapper();
|
||||
|
||||
$zipFile = fopen("s3://$bucket/example.zip", 'w');
|
||||
|
||||
$options = new Archive();
|
||||
$options->setEnableZip64(false);
|
||||
$options->setOutputStream($zipFile);
|
||||
|
||||
$zip = new ZipStream(null, $options);
|
||||
$zip->addFile('file1.txt', 'File1 data');
|
||||
$zip->addFile('file2.txt', 'File2 data');
|
||||
$zip->finish();
|
||||
|
||||
fclose($zipFile);
|
||||
126
vendor/maennchen/zipstream-php/guides/Symfony.rst
vendored
Normal file
126
vendor/maennchen/zipstream-php/guides/Symfony.rst
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
Usage with Symfony
|
||||
===============
|
||||
|
||||
Overview for using ZipStream in Symfony
|
||||
--------
|
||||
|
||||
Using ZipStream in Symfony requires use of Symfony's ``StreamedResponse`` when
|
||||
used in controller actions.
|
||||
|
||||
Wrap your call to the relevant ``ZipStream`` stream method (i.e. ``addFile``,
|
||||
``addFileFromPath``, ``addFileFromStream``) in Symfony's ``StreamedResponse``
|
||||
function passing in any required arguments for your use case.
|
||||
|
||||
Using Symfony's ``StreamedResponse`` will allow Symfony to stream output from
|
||||
ZipStream correctly to users' browsers and avoid a corrupted final zip landing
|
||||
on the users' end.
|
||||
|
||||
Example for using ``ZipStream`` in a controller action to zip stream files
|
||||
stored in an AWS S3 bucket by key:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Aws\S3\S3Client;
|
||||
use ZipStream;
|
||||
|
||||
//...
|
||||
|
||||
/**
|
||||
* @Route("/zipstream", name="zipstream")
|
||||
*/
|
||||
public function zipStreamAction()
|
||||
{
|
||||
//sample test file on s3
|
||||
$s3keys = array(
|
||||
"ziptestfolder/file1.txt"
|
||||
);
|
||||
|
||||
$s3Client = $this->get('app.amazon.s3'); //s3client service
|
||||
$s3Client->registerStreamWrapper(); //required
|
||||
|
||||
//using StreamedResponse to wrap ZipStream functionality for files on AWS s3.
|
||||
$response = new StreamedResponse(function() use($s3keys, $s3Client)
|
||||
{
|
||||
// Define suitable options for ZipStream Archive.
|
||||
$options = new \ZipStream\Option\Archive();
|
||||
$options->setContentType('application/octet-stream');
|
||||
// this is needed to prevent issues with truncated zip files
|
||||
$options->setZeroHeader(true);
|
||||
$options->setComment('test zip file.');
|
||||
|
||||
//initialise zipstream with output zip filename and options.
|
||||
$zip = new ZipStream\ZipStream('test.zip', $options);
|
||||
|
||||
//loop keys - useful for multiple files
|
||||
foreach ($s3keys as $key) {
|
||||
// Get the file name in S3 key so we can save it to the zip
|
||||
//file using the same name.
|
||||
$fileName = basename($key);
|
||||
|
||||
//concatenate s3path.
|
||||
$bucket = 'bucketname'; //replace with your bucket name or get from parameters file.
|
||||
$s3path = "s3://" . $bucket . "/" . $key;
|
||||
|
||||
//addFileFromStream
|
||||
if ($streamRead = fopen($s3path, 'r')) {
|
||||
$zip->addFileFromStream($fileName, $streamRead);
|
||||
} else {
|
||||
die('Could not open stream for reading');
|
||||
}
|
||||
}
|
||||
|
||||
$zip->finish();
|
||||
|
||||
});
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
In the above example, files on AWS S3 are being streamed from S3 to the Symfon
|
||||
application via ``fopen`` call when the s3Client has ``registerStreamWrapper``
|
||||
applied. This stream is then passed to ``ZipStream`` via the
|
||||
``addFileFromStream`` function, which ZipStream then streams as a zip to the
|
||||
client browser via Symfony's ``StreamedResponse``. No Zip is created server
|
||||
side, which makes this approach a more efficient solution for streaming zips to
|
||||
the client browser especially for larger files.
|
||||
|
||||
For the above use case you will need to have installed
|
||||
`aws/aws-sdk-php-symfony <https://github.com/aws/aws-sdk-php-symfony>`_ to
|
||||
support accessing S3 objects in your Symfony web application. This is not
|
||||
required for locally stored files on you server you intend to stream via
|
||||
``ZipStream``.
|
||||
|
||||
See official Symfony documentation for details on
|
||||
`Symfony's StreamedResponse <https://symfony.com/doc/current/components/http_foundation.html#streaming-a-response>`_
|
||||
``Symfony\Component\HttpFoundation\StreamedResponse``.
|
||||
|
||||
Note from `S3 documentation <https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-stream-wrapper.html>`_:
|
||||
|
||||
Streams opened in "r" mode only allow data to be read from the stream, and
|
||||
are not seekable by default. This is so that data can be downloaded from
|
||||
Amazon S3 in a truly streaming manner, where previously read bytes do not
|
||||
need to be buffered into memory. If you need a stream to be seekable, you
|
||||
can pass seekable into the stream context options of a function.
|
||||
|
||||
Make sure to configure your S3 context correctly!
|
||||
|
||||
Uploading a file
|
||||
--------
|
||||
|
||||
You need to add correct permissions
|
||||
(see `#120 <https://github.com/maennchen/ZipStream-PHP/issues/120>`_)
|
||||
|
||||
**example code**
|
||||
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$path = "s3://{$adapter->getBucket()}/{$this->getArchivePath()}";
|
||||
|
||||
// the important bit
|
||||
$outputContext = stream_context_create([
|
||||
's3' => ['ACL' => 'public-read'],
|
||||
]);
|
||||
|
||||
fopen($path, 'w', null, $outputContext);
|
||||
22
vendor/maennchen/zipstream-php/guides/Varnish.rst
vendored
Normal file
22
vendor/maennchen/zipstream-php/guides/Varnish.rst
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Usage with Varnish
|
||||
=============
|
||||
|
||||
Serving a big zip with varnish in between can cause random stream close.
|
||||
This can be solved by adding attached code to the vcl file.
|
||||
|
||||
To avoid the problem, add the following to your varnish config file:
|
||||
|
||||
.. code-block::
|
||||
sub vcl_recv {
|
||||
# Varnish can’t intercept the discussion anymore
|
||||
# helps for streaming big zips
|
||||
if (req.url ~ "\.(tar|gz|zip|7z|exe)$") {
|
||||
return (pipe);
|
||||
}
|
||||
}
|
||||
# Varnish can’t intercept the discussion anymore
|
||||
# helps for streaming big zips
|
||||
sub vcl_pipe {
|
||||
set bereq.http.connection = "close";
|
||||
return (pipe);
|
||||
}
|
||||
100
vendor/maennchen/zipstream-php/guides/index.rst
vendored
Normal file
100
vendor/maennchen/zipstream-php/guides/index.rst
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
ZipStream PHP
|
||||
=============
|
||||
|
||||
A fast and simple streaming zip file downloader for PHP. Using this library will
|
||||
save you from having to write the Zip to disk. You can directly send it to the
|
||||
user, which is much faster. It can work with S3 buckets or any PSR7 Stream.
|
||||
|
||||
.. toctree::
|
||||
|
||||
index
|
||||
Symfony
|
||||
Options
|
||||
StreamOutput
|
||||
FlySystem
|
||||
PSR7Streams
|
||||
Nginx
|
||||
Varnish
|
||||
ContentLength
|
||||
|
||||
Installation
|
||||
---------------
|
||||
|
||||
Simply add a dependency on ``maennchen/zipstream-php`` to your project's
|
||||
``composer.json`` file if you use Composer to manage the dependencies of your
|
||||
project. Use following command to add the package to your project's dependencies:
|
||||
|
||||
.. code-block:: sh
|
||||
composer require maennchen/zipstream-php
|
||||
|
||||
If ``composer install`` yields the following error, your installation is missing
|
||||
the `mbstring extension <https://www.php.net/manual/en/book.mbstring.php>`_,
|
||||
either `install it <https://www.php.net/manual/en/mbstring.installation.php>`_
|
||||
or run the follwoing command:
|
||||
|
||||
.. code-block::
|
||||
Your requirements could not be resolved to an installable set of packages.
|
||||
|
||||
Problem 1
|
||||
- Root composer.json requires PHP extension ext-mbstring * but it is
|
||||
missing from your system. Install or enable PHP's mbstrings extension.
|
||||
|
||||
.. code-block:: sh
|
||||
composer require symfony/polyfill-mbstring
|
||||
|
||||
Usage Intro
|
||||
---------------
|
||||
|
||||
Here's a simple example:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// Autoload the dependencies
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
// enable output of HTTP headers
|
||||
$options = new ZipStream\Option\Archive();
|
||||
$options->setSendHttpHeaders(true);
|
||||
|
||||
// create a new zipstream object
|
||||
$zip = new ZipStream\ZipStream('example.zip', $options);
|
||||
|
||||
// create a file named 'hello.txt'
|
||||
$zip->addFile('hello.txt', 'This is the contents of hello.txt');
|
||||
|
||||
// add a file named 'some_image.jpg' from a local file 'path/to/image.jpg'
|
||||
$zip->addFileFromPath('some_image.jpg', 'path/to/image.jpg');
|
||||
|
||||
// add a file named 'goodbye.txt' from an open stream resource
|
||||
$fp = tmpfile();
|
||||
fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
|
||||
rewind($fp);
|
||||
$zip->addFileFromStream('goodbye.txt', $fp);
|
||||
fclose($fp);
|
||||
|
||||
// finish the zip stream
|
||||
$zip->finish();
|
||||
|
||||
You can also add comments, modify file timestamps, and customize (or
|
||||
disable) the HTTP headers. It is also possible to specify the storage method
|
||||
when adding files, the current default storage method is ``DEFLATE``
|
||||
i.e files are stored with Compression mode 0x08.
|
||||
|
||||
Known Issues
|
||||
---------------
|
||||
|
||||
The native Mac OS archive extraction tool prior to macOS 10.15 might not open
|
||||
archives in some conditions. A workaround is to disable the Zip64 feature with
|
||||
the option ``enableZip64: false``. This limits the archive to 4 Gb and 64k files
|
||||
but will allow users on macOS 10.14 and below to open them without issue.
|
||||
See `#116 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
|
||||
|
||||
The linux ``unzip`` utility might not handle properly unicode characters.
|
||||
It is recommended to extract with another tool like
|
||||
`7-zip <https://www.7-zip.org/>`_.
|
||||
See `#146 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
|
||||
|
||||
It is the responsability of the client code to make sure that files are not
|
||||
saved with the same path, as it is not possible for the library to figure it out
|
||||
while streaming a zip.
|
||||
See `#154 <https://github.com/maennchen/ZipStream-PHP/issues/154>`_.
|
||||
39
vendor/maennchen/zipstream-php/phpdoc.dist.xml
vendored
Normal file
39
vendor/maennchen/zipstream-php/phpdoc.dist.xml
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<phpdocumentor
|
||||
configVersion="3"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://www.phpdoc.org"
|
||||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/phpDocumentor/phpDocumentor/master/data/xsd/phpdoc.xsd"
|
||||
>
|
||||
<title>💾 ZipStream-PHP</title>
|
||||
<paths>
|
||||
<output>docs</output>
|
||||
</paths>
|
||||
<version number="3.0.0">
|
||||
<folder>latest</folder>
|
||||
<api>
|
||||
<source dsn=".">
|
||||
<path>src</path>
|
||||
</source>
|
||||
<output>api</output>
|
||||
<ignore hidden="true" symlinks="true">
|
||||
<path>tests/**/*</path>
|
||||
<path>vendor/**/*</path>
|
||||
</ignore>
|
||||
<extensions>
|
||||
<extension>php</extension>
|
||||
</extensions>
|
||||
<visibility>public</visibility>
|
||||
<default-package-name>ZipStream</default-package-name>
|
||||
<include-source>true</include-source>
|
||||
</api>
|
||||
<guide>
|
||||
<source dsn=".">
|
||||
<path>guides</path>
|
||||
</source>
|
||||
<output>guide</output>
|
||||
</guide>
|
||||
</version>
|
||||
<setting name="guides.enabled" value="true"/>
|
||||
<template name="default" />
|
||||
</phpdocumentor>
|
||||
29
vendor/maennchen/zipstream-php/phpunit.xml.dist
vendored
29
vendor/maennchen/zipstream-php/phpunit.xml.dist
vendored
@@ -1,17 +1,14 @@
|
||||
<phpunit bootstrap="test/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="Application">
|
||||
<directory>test</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-clover" target="clover.xml"/>
|
||||
</logging>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<?xml version="1.0"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Application">
|
||||
<directory>test</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<logging/>
|
||||
</phpunit>
|
||||
|
||||
2
vendor/maennchen/zipstream-php/psalm.xml
vendored
2
vendor/maennchen/zipstream-php/psalm.xml
vendored
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<psalm
|
||||
totallyTyped="false"
|
||||
resolveFromConfigFile="true"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://getpsalm.org/schema/config"
|
||||
@@ -34,7 +33,6 @@
|
||||
<MissingReturnType errorLevel="info" />
|
||||
<MissingPropertyType errorLevel="info" />
|
||||
<InvalidDocblock errorLevel="info" />
|
||||
<MisplacedRequiredParam errorLevel="info" />
|
||||
|
||||
<PropertyNotSetInConstructor errorLevel="info" />
|
||||
<MissingConstructor errorLevel="info" />
|
||||
|
||||
40
vendor/maennchen/zipstream-php/src/Bigint.php
vendored
40
vendor/maennchen/zipstream-php/src/Bigint.php
vendored
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream;
|
||||
@@ -22,22 +23,6 @@ class Bigint
|
||||
$this->fillBytes($value, 0, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the bytes field with int
|
||||
*
|
||||
* @param int $value
|
||||
* @param int $start
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
protected function fillBytes(int $value, int $start, int $count): void
|
||||
{
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->bytes[$start + $i] = $i >= PHP_INT_SIZE ? 0 : $value & 0xFF;
|
||||
$value >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance
|
||||
*
|
||||
@@ -58,7 +43,7 @@ class Bigint
|
||||
*/
|
||||
public static function fromLowHigh(int $low, int $high): self
|
||||
{
|
||||
$bigint = new Bigint();
|
||||
$bigint = new self();
|
||||
$bigint->fillBytes($low, 0, 4);
|
||||
$bigint->fillBytes($high, 4, 4);
|
||||
return $bigint;
|
||||
@@ -108,6 +93,7 @@ class Bigint
|
||||
/**
|
||||
* Check if is over 32
|
||||
*
|
||||
* @psalm-suppress ArgumentTypeCoercion
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
@@ -149,7 +135,7 @@ class Bigint
|
||||
* @param Bigint $other
|
||||
* @return Bigint
|
||||
*/
|
||||
public function add(Bigint $other): Bigint
|
||||
public function add(self $other): self
|
||||
{
|
||||
$result = clone $this;
|
||||
$overflow = false;
|
||||
@@ -165,8 +151,24 @@ class Bigint
|
||||
}
|
||||
}
|
||||
if ($overflow) {
|
||||
throw new OverflowException;
|
||||
throw new OverflowException();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the bytes field with int
|
||||
*
|
||||
* @param int $value
|
||||
* @param int $start
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
protected function fillBytes(int $value, int $start, int $count): void
|
||||
{
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->bytes[$start + $i] = $i >= PHP_INT_SIZE ? 0 : $value & 0xFF;
|
||||
$value >>= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Exception;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Exception;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Exception;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Exception;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Exception;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Exception;
|
||||
|
||||
295
vendor/maennchen/zipstream-php/src/File.php
vendored
295
vendor/maennchen/zipstream-php/src/File.php
vendored
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream;
|
||||
|
||||
use HashContext;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use ZipStream\Exception\EncodingException;
|
||||
use ZipStream\Exception\FileNotFoundException;
|
||||
use ZipStream\Exception\FileNotReadableException;
|
||||
use ZipStream\Exception\OverflowException;
|
||||
@@ -14,13 +15,15 @@ use ZipStream\Option\Version;
|
||||
|
||||
class File
|
||||
{
|
||||
const HASH_ALGORITHM = 'crc32b';
|
||||
public const HASH_ALGORITHM = 'crc32b';
|
||||
|
||||
const BIT_ZERO_HEADER = 0x0008;
|
||||
const BIT_EFS_UTF8 = 0x0800;
|
||||
public const BIT_ZERO_HEADER = 0x0008;
|
||||
|
||||
const COMPUTE = 1;
|
||||
const SEND = 2;
|
||||
public const BIT_EFS_UTF8 = 0x0800;
|
||||
|
||||
public const COMPUTE = 1;
|
||||
|
||||
public const SEND = 2;
|
||||
|
||||
private const CHUNKED_READ_BLOCK_SIZE = 1048576;
|
||||
|
||||
@@ -38,6 +41,7 @@ class File
|
||||
* @var Bigint
|
||||
*/
|
||||
public $len;
|
||||
|
||||
/**
|
||||
* @var Bigint
|
||||
*/
|
||||
@@ -75,8 +79,9 @@ class File
|
||||
* @var resource
|
||||
*/
|
||||
private $deflate;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
* @var HashContext
|
||||
*/
|
||||
private $hash;
|
||||
|
||||
@@ -115,7 +120,7 @@ class File
|
||||
} else {
|
||||
$this->method = $this->zip->opt->getLargeFileMethod();
|
||||
|
||||
$stream = new DeflateStream(fopen($path, 'rb'));
|
||||
$stream = new Stream(fopen($path, 'rb'));
|
||||
$this->processStream($stream);
|
||||
$stream->close();
|
||||
}
|
||||
@@ -160,21 +165,17 @@ class File
|
||||
// Sets Bit 11: Language encoding flag (EFS). If this bit is set,
|
||||
// the filename and comment fields for this file
|
||||
// MUST be encoded using UTF-8. (see APPENDIX D)
|
||||
if (!mb_check_encoding($name, 'UTF-8') ||
|
||||
!mb_check_encoding($comment, 'UTF-8')) {
|
||||
throw new EncodingException(
|
||||
'File name and comment should use UTF-8 ' .
|
||||
'if one of them does not fit into ASCII range.'
|
||||
);
|
||||
if (mb_check_encoding($name, 'UTF-8') &&
|
||||
mb_check_encoding($comment, 'UTF-8')) {
|
||||
$this->bits |= self::BIT_EFS_UTF8;
|
||||
}
|
||||
$this->bits |= self::BIT_EFS_UTF8;
|
||||
}
|
||||
|
||||
if ($this->method->equals(Method::DEFLATE())) {
|
||||
$this->version = Version::DEFLATE();
|
||||
}
|
||||
|
||||
$force = (boolean)($this->bits & self::BIT_ZERO_HEADER) &&
|
||||
$force = (bool)($this->bits & self::BIT_ZERO_HEADER) &&
|
||||
$this->zip->opt->isEnableZip64();
|
||||
|
||||
$footer = $this->buildZip64ExtraBlock($force);
|
||||
@@ -226,83 +227,13 @@ class File
|
||||
return str_replace(['\\', ':', '*', '?', '"', '<', '>', '|'], '_', $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UNIX timestamp to a DOS timestamp.
|
||||
*
|
||||
* @param int $when
|
||||
* @return int DOS Timestamp
|
||||
*/
|
||||
final protected static function dosTime(int $when): int
|
||||
{
|
||||
// get date array for timestamp
|
||||
$d = getdate($when);
|
||||
|
||||
// set lower-bound on dates
|
||||
if ($d['year'] < 1980) {
|
||||
$d = array(
|
||||
'year' => 1980,
|
||||
'mon' => 1,
|
||||
'mday' => 1,
|
||||
'hours' => 0,
|
||||
'minutes' => 0,
|
||||
'seconds' => 0
|
||||
);
|
||||
}
|
||||
|
||||
// remove extra years from 1980
|
||||
$d['year'] -= 1980;
|
||||
|
||||
// return date string
|
||||
return
|
||||
($d['year'] << 25) |
|
||||
($d['mon'] << 21) |
|
||||
($d['mday'] << 16) |
|
||||
($d['hours'] << 11) |
|
||||
($d['minutes'] << 5) |
|
||||
($d['seconds'] >> 1);
|
||||
}
|
||||
|
||||
protected function buildZip64ExtraBlock(bool $force = false): string
|
||||
{
|
||||
|
||||
$fields = [];
|
||||
if ($this->len->isOver32($force)) {
|
||||
$fields[] = ['P', $this->len]; // Length of original data
|
||||
}
|
||||
|
||||
if ($this->len->isOver32($force)) {
|
||||
$fields[] = ['P', $this->zlen]; // Length of compressed data
|
||||
}
|
||||
|
||||
if ($this->ofs->isOver32()) {
|
||||
$fields[] = ['P', $this->ofs]; // Offset of local header record
|
||||
}
|
||||
|
||||
if (!empty($fields)) {
|
||||
if (!$this->zip->opt->isEnableZip64()) {
|
||||
throw new OverflowException();
|
||||
}
|
||||
|
||||
array_unshift(
|
||||
$fields,
|
||||
['v', 0x0001], // 64 bit extension
|
||||
['v', count($fields) * 8] // Length of data block
|
||||
);
|
||||
$this->version = Version::ZIP64();
|
||||
}
|
||||
|
||||
return ZipStream::packFields($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and send data descriptor footer for this file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function addFileFooter(): void
|
||||
{
|
||||
|
||||
if ($this->bits & self::BIT_ZERO_HEADER) {
|
||||
// compressed and uncompressed size
|
||||
$sizeFormat = 'V';
|
||||
@@ -337,6 +268,130 @@ class File
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send CDR record for specified file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCdrFile(): string
|
||||
{
|
||||
$name = static::filterFilename($this->name);
|
||||
|
||||
// get attributes
|
||||
$comment = $this->opt->getComment();
|
||||
|
||||
// get dos timestamp
|
||||
$time = static::dosTime($this->opt->getTime()->getTimestamp());
|
||||
|
||||
$footer = $this->buildZip64ExtraBlock();
|
||||
|
||||
$fields = [
|
||||
['V', ZipStream::CDR_FILE_SIGNATURE], // Central file header signature
|
||||
['v', ZipStream::ZIP_VERSION_MADE_BY], // Made by version
|
||||
['v', $this->version->getValue()], // Extract by version
|
||||
['v', $this->bits], // General purpose bit flags - data descriptor flag set
|
||||
['v', $this->method->getValue()], // Compression method
|
||||
['V', $time], // Timestamp (DOS Format)
|
||||
['V', $this->crc], // CRC32
|
||||
['V', $this->zlen->getLowFF()], // Compressed Data Length
|
||||
['V', $this->len->getLowFF()], // Original Data Length
|
||||
['v', strlen($name)], // Length of filename
|
||||
['v', strlen($footer)], // Extra data len (see above)
|
||||
['v', strlen($comment)], // Length of comment
|
||||
['v', 0], // Disk number
|
||||
['v', 0], // Internal File Attributes
|
||||
['V', 32], // External File Attributes
|
||||
['V', $this->ofs->getLowFF()], // Relative offset of local header
|
||||
];
|
||||
|
||||
// pack fields, then append name and comment
|
||||
$header = ZipStream::packFields($fields);
|
||||
|
||||
return $header . $name . $footer . $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Bigint
|
||||
*/
|
||||
public function getTotalLength(): Bigint
|
||||
{
|
||||
return $this->totalLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UNIX timestamp to a DOS timestamp.
|
||||
*
|
||||
* @param int $when
|
||||
* @return int DOS Timestamp
|
||||
*/
|
||||
final protected static function dosTime(int $when): int
|
||||
{
|
||||
// get date array for timestamp
|
||||
$d = getdate($when);
|
||||
|
||||
// set lower-bound on dates
|
||||
if ($d['year'] < 1980) {
|
||||
$d = [
|
||||
'year' => 1980,
|
||||
'mon' => 1,
|
||||
'mday' => 1,
|
||||
'hours' => 0,
|
||||
'minutes' => 0,
|
||||
'seconds' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
// remove extra years from 1980
|
||||
$d['year'] -= 1980;
|
||||
|
||||
// return date string
|
||||
return
|
||||
($d['year'] << 25) |
|
||||
($d['mon'] << 21) |
|
||||
($d['mday'] << 16) |
|
||||
($d['hours'] << 11) |
|
||||
($d['minutes'] << 5) |
|
||||
($d['seconds'] >> 1);
|
||||
}
|
||||
|
||||
protected function buildZip64ExtraBlock(bool $force = false): string
|
||||
{
|
||||
$fields = [];
|
||||
if ($this->len->isOver32($force)) {
|
||||
$fields[] = ['P', $this->len]; // Length of original data
|
||||
}
|
||||
|
||||
if ($this->len->isOver32($force)) {
|
||||
$fields[] = ['P', $this->zlen]; // Length of compressed data
|
||||
}
|
||||
|
||||
if ($this->ofs->isOver32()) {
|
||||
$fields[] = ['P', $this->ofs]; // Offset of local header record
|
||||
}
|
||||
|
||||
if (!empty($fields)) {
|
||||
if (!$this->zip->opt->isEnableZip64()) {
|
||||
throw new OverflowException();
|
||||
}
|
||||
|
||||
array_unshift(
|
||||
$fields,
|
||||
['v', 0x0001], // 64 bit extension
|
||||
['v', count($fields) * 8] // Length of data block
|
||||
);
|
||||
$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);
|
||||
}
|
||||
|
||||
protected function processStreamWithZeroHeader(StreamInterface $stream): void
|
||||
{
|
||||
$this->bits |= self::BIT_ZERO_HEADER;
|
||||
@@ -354,7 +409,7 @@ class File
|
||||
$data = $stream->read(self::CHUNKED_READ_BLOCK_SIZE);
|
||||
$total += strlen($data);
|
||||
if ($size > 0 && $total > $size) {
|
||||
$data = substr($data, 0 , strlen($data)-($total - $size));
|
||||
$data = substr($data, 0, strlen($data)-($total - $size));
|
||||
}
|
||||
$this->deflateData($stream, $data, $options);
|
||||
if ($options & self::SEND) {
|
||||
@@ -366,7 +421,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,
|
||||
@@ -407,71 +463,8 @@ class File
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send CDR record for specified file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCdrFile(): string
|
||||
{
|
||||
$name = static::filterFilename($this->name);
|
||||
|
||||
// get attributes
|
||||
$comment = $this->opt->getComment();
|
||||
|
||||
// get dos timestamp
|
||||
$time = static::dosTime($this->opt->getTime()->getTimestamp());
|
||||
|
||||
$footer = $this->buildZip64ExtraBlock();
|
||||
|
||||
$fields = [
|
||||
['V', ZipStream::CDR_FILE_SIGNATURE], // Central file header signature
|
||||
['v', ZipStream::ZIP_VERSION_MADE_BY], // Made by version
|
||||
['v', $this->version->getValue()], // Extract by version
|
||||
['v', $this->bits], // General purpose bit flags - data descriptor flag set
|
||||
['v', $this->method->getValue()], // Compression method
|
||||
['V', $time], // Timestamp (DOS Format)
|
||||
['V', $this->crc], // CRC32
|
||||
['V', $this->zlen->getLowFF()], // Compressed Data Length
|
||||
['V', $this->len->getLowFF()], // Original Data Length
|
||||
['v', strlen($name)], // Length of filename
|
||||
['v', strlen($footer)], // Extra data len (see above)
|
||||
['v', strlen($comment)], // Length of comment
|
||||
['v', 0], // Disk number
|
||||
['v', 0], // Internal File Attributes
|
||||
['V', 32], // External File Attributes
|
||||
['V', $this->ofs->getLowFF()] // Relative offset of local header
|
||||
];
|
||||
|
||||
// pack fields, then append name and comment
|
||||
$header = ZipStream::packFields($fields);
|
||||
|
||||
return $header . $name . $footer . $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Bigint
|
||||
*/
|
||||
public function getTotalLength(): Bigint
|
||||
{
|
||||
return $this->totalLength;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Option;
|
||||
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
final class Archive
|
||||
{
|
||||
const DEFAULT_DEFLATE_LEVEL = 6;
|
||||
public const DEFAULT_DEFLATE_LEVEL = 6;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $comment = '';
|
||||
|
||||
/**
|
||||
* Size, in bytes, of the largest file to try
|
||||
* and load into memory (used by
|
||||
@@ -20,6 +25,7 @@ final class Archive
|
||||
* @var int
|
||||
*/
|
||||
private $largeFileSize = 20 * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* How to handle large files. Legal values are
|
||||
* Method::STORE() (the default), or
|
||||
@@ -32,6 +38,7 @@ final class Archive
|
||||
* @var Method
|
||||
*/
|
||||
private $largeFileMethod;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether or not to send
|
||||
* the HTTP headers for this file.
|
||||
@@ -39,12 +46,14 @@ final class Archive
|
||||
* @var bool
|
||||
*/
|
||||
private $sendHttpHeaders = false;
|
||||
|
||||
/**
|
||||
* The method called to send headers
|
||||
*
|
||||
* @var Callable
|
||||
*/
|
||||
private $httpHeaderCallback = 'header';
|
||||
|
||||
/**
|
||||
* Enable Zip64 extension, supporting very large
|
||||
* archives (any size > 4 GB or file count > 64k)
|
||||
@@ -52,6 +61,7 @@ final class Archive
|
||||
* @var bool
|
||||
*/
|
||||
private $enableZip64 = true;
|
||||
|
||||
/**
|
||||
* Enable streaming files with single read where
|
||||
* general purpose bit 3 indicates local file header
|
||||
@@ -62,6 +72,7 @@ final class Archive
|
||||
* @var bool
|
||||
*/
|
||||
private $zeroHeader = false;
|
||||
|
||||
/**
|
||||
* Enable reading file stat for determining file size.
|
||||
* When a 32-bit system reads file size that is
|
||||
@@ -75,11 +86,13 @@ final class Archive
|
||||
* @var bool
|
||||
*/
|
||||
private $statFiles = true;
|
||||
|
||||
/**
|
||||
* Enable flush after every write to output stream.
|
||||
* @var bool
|
||||
*/
|
||||
private $flushOutput = false;
|
||||
|
||||
/**
|
||||
* HTTP Content-Disposition. Defaults to
|
||||
* 'attachment', where
|
||||
@@ -91,6 +104,7 @@ final class Archive
|
||||
* @var string
|
||||
*/
|
||||
private $contentDisposition = 'attachment';
|
||||
|
||||
/**
|
||||
* Note that this does nothing if you are
|
||||
* not sending HTTP headers.
|
||||
@@ -98,13 +112,14 @@ final class Archive
|
||||
* @var string
|
||||
*/
|
||||
private $contentType = 'application/x-zip';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $deflateLevel = 6;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
* @var StreamInterface|resource
|
||||
*/
|
||||
private $outputStream;
|
||||
|
||||
@@ -157,12 +172,12 @@ final class Archive
|
||||
$this->sendHttpHeaders = $sendHttpHeaders;
|
||||
}
|
||||
|
||||
public function getHttpHeaderCallback(): Callable
|
||||
public function getHttpHeaderCallback(): callable
|
||||
{
|
||||
return $this->httpHeaderCallback;
|
||||
}
|
||||
|
||||
public function setHttpHeaderCallback(Callable $httpHeaderCallback): void
|
||||
public function setHttpHeaderCallback(callable $httpHeaderCallback): void
|
||||
{
|
||||
$this->httpHeaderCallback = $httpHeaderCallback;
|
||||
}
|
||||
@@ -228,7 +243,7 @@ final class Archive
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
* @return StreamInterface|resource
|
||||
*/
|
||||
public function getOutputStream()
|
||||
{
|
||||
@@ -236,7 +251,7 @@ final class Archive
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $outputStream
|
||||
* @param StreamInterface|resource $outputStream
|
||||
*/
|
||||
public function setOutputStream($outputStream): void
|
||||
{
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Option;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
|
||||
final class File
|
||||
{
|
||||
@@ -11,18 +13,22 @@ final class File
|
||||
* @var string
|
||||
*/
|
||||
private $comment = '';
|
||||
|
||||
/**
|
||||
* @var Method
|
||||
*/
|
||||
private $method;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $deflateLevel;
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
* @var DateTimeInterface
|
||||
*/
|
||||
private $time;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@@ -83,17 +89,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;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Option;
|
||||
@@ -11,9 +12,12 @@ use MyCLabs\Enum\Enum;
|
||||
* @method static STORE(): Method
|
||||
* @method static DEFLATE(): Method
|
||||
* @psalm-immutable
|
||||
* @psalm-template int
|
||||
* @extends Enum<int>
|
||||
*/
|
||||
class Method extends Enum
|
||||
{
|
||||
const STORE = 0x00;
|
||||
const DEFLATE = 0x08;
|
||||
public const STORE = 0x00;
|
||||
|
||||
public const DEFLATE = 0x08;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream\Option;
|
||||
@@ -13,10 +14,14 @@ use MyCLabs\Enum\Enum;
|
||||
* @method static DEFLATE(): Version
|
||||
* @method static ZIP64(): Version
|
||||
* @psalm-immutable
|
||||
* @psalm-template int
|
||||
* @extends Enum<int>
|
||||
*/
|
||||
class Version extends Enum
|
||||
{
|
||||
const STORE = 0x000A; // 1.00
|
||||
const DEFLATE = 0x0014; // 2.00
|
||||
const ZIP64 = 0x002D; // 4.50
|
||||
public const STORE = 0x000A; // 1.00
|
||||
|
||||
public const DEFLATE = 0x0014; // 2.00
|
||||
|
||||
public const ZIP64 = 0x002D; // 4.50
|
||||
}
|
||||
|
||||
92
vendor/maennchen/zipstream-php/src/Stream.php
vendored
92
vendor/maennchen/zipstream-php/src/Stream.php
vendored
@@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream;
|
||||
|
||||
use function mb_strlen;
|
||||
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -22,6 +25,29 @@ class Stream implements StreamInterface
|
||||
$this->stream = $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all data from the stream into a string, from the beginning to end.
|
||||
*
|
||||
* This method MUST attempt to seek to the beginning of the stream before
|
||||
* reading data and read the stream until the end is reached.
|
||||
*
|
||||
* Warning: This could attempt to load a large amount of data into memory.
|
||||
*
|
||||
* This method MUST NOT raise an exception in order to conform with PHP's
|
||||
* string casting operations.
|
||||
*
|
||||
* @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
try {
|
||||
$this->seek(0);
|
||||
} catch (RuntimeException $e) {
|
||||
}
|
||||
return (string) stream_get_contents($this->stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the stream and any underlying resources.
|
||||
*
|
||||
@@ -49,28 +75,6 @@ class Stream implements StreamInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all data from the stream into a string, from the beginning to end.
|
||||
*
|
||||
* This method MUST attempt to seek to the beginning of the stream before
|
||||
* reading data and read the stream until the end is reached.
|
||||
*
|
||||
* Warning: This could attempt to load a large amount of data into memory.
|
||||
*
|
||||
* This method MUST NOT raise an exception in order to conform with PHP's
|
||||
* string casting operations.
|
||||
*
|
||||
* @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
try {
|
||||
$this->seek(0);
|
||||
} catch (\RuntimeException $e) {}
|
||||
return (string) stream_get_contents($this->stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek to a position in the stream.
|
||||
*
|
||||
@@ -81,15 +85,15 @@ 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
|
||||
{
|
||||
if (!$this->isSeekable()) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
if (fseek($this->stream, $offset, $whence) !== 0) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,13 +140,13 @@ 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
|
||||
{
|
||||
$position = ftell($this->stream);
|
||||
if ($position === false) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return $position;
|
||||
}
|
||||
@@ -165,7 +169,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,17 +181,17 @@ 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
|
||||
{
|
||||
if (!$this->isWritable()) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
if (fwrite($this->stream, $string) === false) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return \mb_strlen($string);
|
||||
return mb_strlen($string);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +201,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,16 +216,16 @@ class Stream implements StreamInterface
|
||||
* call returns fewer bytes.
|
||||
* @return string Returns the data read from the stream, or an empty string
|
||||
* if no bytes are available.
|
||||
* @throws \RuntimeException if an error occurs.
|
||||
* @throws RuntimeException if an error occurs.
|
||||
*/
|
||||
public function read($length): string
|
||||
{
|
||||
if (!$this->isReadable()) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
$result = fread($this->stream, $length);
|
||||
if ($result === false) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -229,24 +237,28 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remaining contents in a string
|
||||
*
|
||||
* @return string
|
||||
* @throws \RuntimeException if unable to read or an error occurs while
|
||||
* @throws RuntimeException if unable to read or an error occurs while
|
||||
* reading.
|
||||
*/
|
||||
public function getContents(): string
|
||||
{
|
||||
if (!$this->isReadable()) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
$result = stream_get_contents($this->stream);
|
||||
if ($result === false) {
|
||||
throw new RuntimeException;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
157
vendor/maennchen/zipstream-php/src/ZipStream.php
vendored
157
vendor/maennchen/zipstream-php/src/ZipStream.php
vendored
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStream;
|
||||
@@ -80,19 +81,24 @@ class ZipStream
|
||||
* to prevent file permissions issues upon extract (see #84)
|
||||
* 0x603 is 00000110 00000011 in binary, so 6 and 3
|
||||
*/
|
||||
const ZIP_VERSION_MADE_BY = 0x603;
|
||||
public const ZIP_VERSION_MADE_BY = 0x603;
|
||||
|
||||
/**
|
||||
* The following signatures end with 0x4b50, which in ASCII is PK,
|
||||
* The following signatures end with 0x4b50, which in ASCII is PK,
|
||||
* the initials of the inventor Phil Katz.
|
||||
* See https://en.wikipedia.org/wiki/Zip_(file_format)#File_headers
|
||||
*/
|
||||
const FILE_HEADER_SIGNATURE = 0x04034b50;
|
||||
const CDR_FILE_SIGNATURE = 0x02014b50;
|
||||
const CDR_EOF_SIGNATURE = 0x06054b50;
|
||||
const DATA_DESCRIPTOR_SIGNATURE = 0x08074b50;
|
||||
const ZIP64_CDR_EOF_SIGNATURE = 0x06064b50;
|
||||
const ZIP64_CDR_LOCATOR_SIGNATURE = 0x07064b50;
|
||||
public const FILE_HEADER_SIGNATURE = 0x04034b50;
|
||||
|
||||
public const CDR_FILE_SIGNATURE = 0x02014b50;
|
||||
|
||||
public const CDR_EOF_SIGNATURE = 0x06054b50;
|
||||
|
||||
public const DATA_DESCRIPTOR_SIGNATURE = 0x08074b50;
|
||||
|
||||
public const ZIP64_CDR_EOF_SIGNATURE = 0x06064b50;
|
||||
|
||||
public const ZIP64_CDR_LOCATOR_SIGNATURE = 0x07064b50;
|
||||
|
||||
/**
|
||||
* Global Options
|
||||
@@ -293,7 +299,7 @@ class ZipStream
|
||||
$options->defaultTo($this->opt);
|
||||
|
||||
$file = new File($this, $name, $options);
|
||||
$file->processStream(new DeflateStream($stream));
|
||||
$file->processStream(new Stream($stream));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,12 +318,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
|
||||
*/
|
||||
@@ -378,34 +381,6 @@ class ZipStream
|
||||
$this->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send ZIP64 CDR EOF (Central Directory Record End-of-File) record.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addCdr64Eof(): void
|
||||
{
|
||||
$num_files = count($this->files);
|
||||
$cdr_length = $this->cdr_ofs;
|
||||
$cdr_offset = $this->ofs;
|
||||
|
||||
$fields = [
|
||||
['V', static::ZIP64_CDR_EOF_SIGNATURE], // ZIP64 end of central file header signature
|
||||
['P', 44], // Length of data below this header (length of block - 12) = 44
|
||||
['v', static::ZIP_VERSION_MADE_BY], // Made by version
|
||||
['v', Version::ZIP64], // Extract by version
|
||||
['V', 0x00], // disk number
|
||||
['V', 0x00], // no of disks
|
||||
['P', $num_files], // no of entries on disk
|
||||
['P', $num_files], // no of entries in cdr
|
||||
['P', $cdr_length], // CDR size
|
||||
['P', $cdr_offset], // CDR offset
|
||||
];
|
||||
|
||||
$ret = static::packFields($fields);
|
||||
$this->send($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a format string and argument list for pack(), then call
|
||||
* pack() and return the result.
|
||||
@@ -459,7 +434,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
|
||||
@@ -473,6 +454,62 @@ class ZipStream
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this file larger than large_file_size?
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function isLargeFile(string $path): bool
|
||||
{
|
||||
if (!$this->opt->isStatFiles()) {
|
||||
return false;
|
||||
}
|
||||
$stat = stat($path);
|
||||
return $stat['size'] > $this->opt->getLargeFileSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save file attributes for trailing CDR record.
|
||||
*
|
||||
* @param File $file
|
||||
* @return void
|
||||
*/
|
||||
public function addToCdr(File $file): void
|
||||
{
|
||||
$file->ofs = $this->ofs;
|
||||
$this->ofs = $this->ofs->add($file->getTotalLength());
|
||||
$this->files[] = $file->getCdrFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send ZIP64 CDR EOF (Central Directory Record End-of-File) record.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addCdr64Eof(): void
|
||||
{
|
||||
$num_files = count($this->files);
|
||||
$cdr_length = $this->cdr_ofs;
|
||||
$cdr_offset = $this->ofs;
|
||||
|
||||
$fields = [
|
||||
['V', static::ZIP64_CDR_EOF_SIGNATURE], // ZIP64 end of central file header signature
|
||||
['P', 44], // Length of data below this header (length of block - 12) = 44
|
||||
['v', static::ZIP_VERSION_MADE_BY], // Made by version
|
||||
['v', Version::ZIP64], // Extract by version
|
||||
['V', 0x00], // disk number
|
||||
['V', 0x00], // no of disks
|
||||
['P', $num_files], // no of entries on disk
|
||||
['P', $num_files], // no of entries in cdr
|
||||
['P', $cdr_length], // CDR size
|
||||
['P', $cdr_offset], // CDR offset
|
||||
];
|
||||
|
||||
$ret = static::packFields($fields);
|
||||
$this->send($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send HTTP headers for this stream.
|
||||
*
|
||||
@@ -492,13 +529,13 @@ class ZipStream
|
||||
$disposition .= "; filename*=UTF-8''{$urlencoded}";
|
||||
}
|
||||
|
||||
$headers = array(
|
||||
$headers = [
|
||||
'Content-Type' => $this->opt->getContentType(),
|
||||
'Content-Disposition' => $disposition,
|
||||
'Pragma' => 'public',
|
||||
'Cache-Control' => 'public, must-revalidate',
|
||||
'Content-Transfer-Encoding' => 'binary'
|
||||
);
|
||||
'Content-Transfer-Encoding' => 'binary',
|
||||
];
|
||||
|
||||
$call = $this->opt->getHttpHeaderCallback();
|
||||
foreach ($headers as $key => $val) {
|
||||
@@ -568,32 +605,4 @@ class ZipStream
|
||||
$this->cdr_ofs = new Bigint();
|
||||
$this->opt = new ArchiveOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this file larger than large_file_size?
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function isLargeFile(string $path): bool
|
||||
{
|
||||
if (!$this->opt->isStatFiles()) {
|
||||
return false;
|
||||
}
|
||||
$stat = stat($path);
|
||||
return $stat['size'] > $this->opt->getLargeFileSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save file attributes for trailing CDR record.
|
||||
*
|
||||
* @param File $file
|
||||
* @return void
|
||||
*/
|
||||
public function addToCdr(File $file): void
|
||||
{
|
||||
$file->ofs = $this->ofs;
|
||||
$this->ofs = $this->ofs->add($file->getTotalLength());
|
||||
$this->files[] = $file->getCdrFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BigintTest;
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZipStreamTest;
|
||||
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use ReflectionClass;
|
||||
use ZipArchive;
|
||||
use ZipStream\File;
|
||||
use ZipStream\Option\Archive as ArchiveOptions;
|
||||
use ZipStream\Option\File as FileOptions;
|
||||
use ZipStream\Option\Method;
|
||||
use ZipStream\Stream;
|
||||
use ZipStream\ZipStream;
|
||||
|
||||
/**
|
||||
@@ -17,9 +23,6 @@ use ZipStream\ZipStream;
|
||||
*/
|
||||
class ZipStreamTest extends TestCase
|
||||
{
|
||||
const OSX_ARCHIVE_UTILITY =
|
||||
'/System/Library/CoreServices/Applications/Archive Utility.app/Contents/MacOS/Archive Utility';
|
||||
|
||||
public function testFileNotFoundException(): void
|
||||
{
|
||||
$this->expectException(\ZipStream\Exception\FileNotFoundException::class);
|
||||
@@ -35,7 +38,7 @@ class ZipStreamTest extends TestCase
|
||||
// create new virtual filesystem
|
||||
$root = vfsStream::setup('vfs');
|
||||
// create a virtual file with no permissions
|
||||
$file = vfsStream::newFile('foo.txt', 0000)->at($root)->setContent('bar');
|
||||
$file = vfsStream::newFile('foo.txt', 0)->at($root)->setContent('bar');
|
||||
$zip = new ZipStream();
|
||||
$this->expectException(\ZipStream\Exception\FileNotReadableException::class);
|
||||
$zip->addFileFromPath('foo.txt', $file->url());
|
||||
@@ -44,7 +47,7 @@ class ZipStreamTest extends TestCase
|
||||
public function testDostime(): void
|
||||
{
|
||||
// Allows testing of protected method
|
||||
$class = new \ReflectionClass(File::class);
|
||||
$class = new ReflectionClass(File::class);
|
||||
$method = $class->getMethod('dostime');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@@ -75,81 +78,12 @@ class ZipStreamTest extends TestCase
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(['sample.txt', 'test/sample.txt'], $files);
|
||||
$this->assertSame(['sample.txt', 'test' . DIRECTORY_SEPARATOR . 'sample.txt'], $files);
|
||||
|
||||
$this->assertStringEqualsFile($tmpDir . '/sample.txt', 'Sample String Data');
|
||||
$this->assertStringEqualsFile($tmpDir . '/test/sample.txt', 'More Simple Sample Data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getTmpFileStream(): array
|
||||
{
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'zipstreamtest');
|
||||
$stream = fopen($tmp, 'wb+');
|
||||
|
||||
return array($tmp, $stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tmp
|
||||
* @return string
|
||||
*/
|
||||
protected function validateAndExtractZip($tmp): string
|
||||
{
|
||||
$tmpDir = $this->getTmpDir();
|
||||
|
||||
$zipArch = new \ZipArchive;
|
||||
$res = $zipArch->open($tmp);
|
||||
|
||||
if ($res !== true) {
|
||||
$this->fail("Failed to open {$tmp}. Code: $res");
|
||||
|
||||
return $tmpDir;
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $zipArch->status);
|
||||
$this->assertEquals(0, $zipArch->statusSys);
|
||||
|
||||
$zipArch->extractTo($tmpDir);
|
||||
$zipArch->close();
|
||||
|
||||
return $tmpDir;
|
||||
}
|
||||
|
||||
protected function getTmpDir(): string
|
||||
{
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'zipstreamtest');
|
||||
unlink($tmp);
|
||||
mkdir($tmp) or $this->fail('Failed to make directory');
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getRecursiveFileList(string $path): array
|
||||
{
|
||||
$data = array();
|
||||
$path = (string)realpath($path);
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
|
||||
|
||||
$pathLen = strlen($path);
|
||||
foreach ($files as $file) {
|
||||
$filePath = $file->getRealPath();
|
||||
if (!is_dir($filePath)) {
|
||||
$data[] = substr($filePath, $pathLen + 1);
|
||||
}
|
||||
}
|
||||
|
||||
sort($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testAddFileUtf8NameComment(): void
|
||||
{
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
@@ -176,19 +110,17 @@ class ZipStreamTest extends TestCase
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(array($name), $files);
|
||||
$this->assertSame([$name], $files);
|
||||
$this->assertStringEqualsFile($tmpDir . '/' . $name, $content);
|
||||
|
||||
$zipArch = new \ZipArchive();
|
||||
$zipArch = new ZipArchive();
|
||||
$zipArch->open($tmp);
|
||||
$this->assertEquals($comment, $zipArch->getCommentName($name));
|
||||
$this->assertSame($comment, $zipArch->getCommentName($name));
|
||||
}
|
||||
|
||||
public function testAddFileUtf8NameNonUtfComment(): void
|
||||
{
|
||||
$this->expectException(\ZipStream\Exception\EncodingException::class);
|
||||
|
||||
$stream = $this->getTmpFileStream()[1];
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
|
||||
$options = new ArchiveOptions();
|
||||
$options->setOutputStream($stream);
|
||||
@@ -197,33 +129,66 @@ class ZipStreamTest extends TestCase
|
||||
|
||||
$name = 'á.txt';
|
||||
$content = 'any';
|
||||
$comment = 'á';
|
||||
$comment = mb_convert_encoding('á', 'ISO-8859-2', 'UTF-8');
|
||||
|
||||
$fileOptions = new FileOptions();
|
||||
$fileOptions->setComment(mb_convert_encoding($comment, 'ISO-8859-2', 'UTF-8'));
|
||||
|
||||
$zip->addFile($name, $content, $fileOptions);
|
||||
}
|
||||
|
||||
public function testAddFileNonUtf8NameUtfComment(): void
|
||||
{
|
||||
$this->expectException(\ZipStream\Exception\EncodingException::class);
|
||||
|
||||
$stream = $this->getTmpFileStream()[1];
|
||||
|
||||
$options = new ArchiveOptions();
|
||||
$options->setOutputStream($stream);
|
||||
|
||||
$zip = new ZipStream(null, $options);
|
||||
|
||||
$name = 'á.txt';
|
||||
$content = 'any';
|
||||
$comment = 'á';
|
||||
// @see https://libzip.org/documentation/zip_file_get_comment.html
|
||||
//
|
||||
// mb_convert_encoding hasn't CP437.
|
||||
// nearly CP850 (DOS-Latin-1)
|
||||
$guessComment = mb_convert_encoding($comment, 'UTF-8', 'CP850');
|
||||
|
||||
$fileOptions = new FileOptions();
|
||||
$fileOptions->setComment($comment);
|
||||
|
||||
$zip->addFile(mb_convert_encoding($name, 'ISO-8859-2', 'UTF-8'), $content, $fileOptions);
|
||||
$zip->addFile($name, $content, $fileOptions);
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
$zipArch = new ZipArchive();
|
||||
$zipArch->open($tmp);
|
||||
$this->assertSame($guessComment, $zipArch->getCommentName($name));
|
||||
$this->assertSame($comment, $zipArch->getCommentName($name, ZipArchive::FL_ENC_RAW));
|
||||
}
|
||||
|
||||
public function testAddFileNonUtf8NameUtfComment(): void
|
||||
{
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
|
||||
$options = new ArchiveOptions();
|
||||
$options->setOutputStream($stream);
|
||||
|
||||
$zip = new ZipStream(null, $options);
|
||||
|
||||
$name = mb_convert_encoding('á.txt', 'ISO-8859-2', 'UTF-8');
|
||||
$content = 'any';
|
||||
$comment = 'á';
|
||||
|
||||
// @see https://libzip.org/documentation/zip_get_name.html
|
||||
//
|
||||
// mb_convert_encoding hasn't CP437.
|
||||
// nearly CP850 (DOS-Latin-1)
|
||||
$guessName = mb_convert_encoding($name, 'UTF-8', 'CP850');
|
||||
|
||||
$fileOptions = new FileOptions();
|
||||
$fileOptions->setComment($comment);
|
||||
|
||||
$zip->addFile($name, $content, $fileOptions);
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
|
||||
$this->assertNotSame([$name], $files);
|
||||
$this->assertSame([$guessName], $files);
|
||||
$this->assertStringEqualsFile($tmpDir . '/' . $guessName, $content);
|
||||
|
||||
$zipArch = new ZipArchive();
|
||||
$zipArch->open($tmp);
|
||||
$this->assertSame($guessName, $zipArch->getNameIndex(0));
|
||||
$this->assertSame($name, $zipArch->getNameIndex(0, ZipArchive::FL_ENC_RAW));
|
||||
$this->assertSame($comment, $zipArch->getCommentName($guessName));
|
||||
}
|
||||
|
||||
public function testAddFileWithStorageMethod(): void
|
||||
@@ -243,45 +208,17 @@ class ZipStreamTest extends TestCase
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
$zipArch = new \ZipArchive();
|
||||
$zipArch = new ZipArchive();
|
||||
$zipArch->open($tmp);
|
||||
|
||||
$sample1 = $zipArch->statName('sample.txt');
|
||||
$sample12 = $zipArch->statName('test/sample.txt');
|
||||
$this->assertEquals($sample1['comp_method'], Method::STORE);
|
||||
$this->assertEquals($sample12['comp_method'], Method::DEFLATE);
|
||||
$this->assertSame($sample1['comp_method'], Method::STORE);
|
||||
$this->assertSame($sample12['comp_method'], Method::DEFLATE);
|
||||
|
||||
$zipArch->close();
|
||||
}
|
||||
|
||||
public function testDecompressFileWithMacUnarchiver(): void
|
||||
{
|
||||
if (!file_exists(self::OSX_ARCHIVE_UTILITY)) {
|
||||
$this->markTestSkipped('The Mac OSX Archive Utility is not available.');
|
||||
}
|
||||
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
|
||||
$options = new ArchiveOptions();
|
||||
$options->setOutputStream($stream);
|
||||
|
||||
$zip = new ZipStream(null, $options);
|
||||
|
||||
$folder = uniqid('', true);
|
||||
|
||||
$zip->addFile($folder . '/sample.txt', 'Sample Data');
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
exec(escapeshellarg(self::OSX_ARCHIVE_UTILITY) . ' ' . escapeshellarg($tmp), $output, $returnStatus);
|
||||
|
||||
$this->assertEquals(0, $returnStatus);
|
||||
$this->assertCount(0, $output);
|
||||
|
||||
$this->assertFileExists(dirname($tmp) . '/' . $folder . '/sample.txt');
|
||||
$this->assertStringEqualsFile(dirname($tmp) . '/' . $folder . '/sample.txt', 'Sample Data');
|
||||
}
|
||||
|
||||
public function testAddFileFromPath(): void
|
||||
{
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
@@ -307,7 +244,7 @@ class ZipStreamTest extends TestCase
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(array('sample.txt', 'test/sample.txt'), $files);
|
||||
$this->assertSame(['sample.txt', 'test' . DIRECTORY_SEPARATOR . 'sample.txt'], $files);
|
||||
|
||||
$this->assertStringEqualsFile($tmpDir . '/sample.txt', 'Sample String Data');
|
||||
$this->assertStringEqualsFile($tmpDir . '/test/sample.txt', 'More Simple Sample Data');
|
||||
@@ -338,14 +275,14 @@ class ZipStreamTest extends TestCase
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
$zipArch = new \ZipArchive();
|
||||
$zipArch = new ZipArchive();
|
||||
$zipArch->open($tmp);
|
||||
|
||||
$sample1 = $zipArch->statName('sample.txt');
|
||||
$this->assertEquals(Method::STORE, $sample1['comp_method']);
|
||||
$this->assertSame(Method::STORE, $sample1['comp_method']);
|
||||
|
||||
$sample2 = $zipArch->statName('test/sample.txt');
|
||||
$this->assertEquals(Method::DEFLATE, $sample2['comp_method']);
|
||||
$this->assertSame(Method::DEFLATE, $sample2['comp_method']);
|
||||
|
||||
$zipArch->close();
|
||||
}
|
||||
@@ -366,42 +303,6 @@ class ZipStreamTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected function addLargeFileFileFromPath($method, $zeroHeader, $zip64): void
|
||||
{
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
|
||||
$options = new ArchiveOptions();
|
||||
$options->setOutputStream($stream);
|
||||
$options->setLargeFileMethod($method);
|
||||
$options->setLargeFileSize(5);
|
||||
$options->setZeroHeader($zeroHeader);
|
||||
$options->setEnableZip64($zip64);
|
||||
|
||||
$zip = new ZipStream(null, $options);
|
||||
|
||||
[$tmpExample, $streamExample] = $this->getTmpFileStream();
|
||||
for ($i = 0; $i <= 10000; $i++) {
|
||||
fwrite($streamExample, sha1((string)$i));
|
||||
if ($i % 100 === 0) {
|
||||
fwrite($streamExample, "\n");
|
||||
}
|
||||
}
|
||||
fclose($streamExample);
|
||||
$shaExample = sha1_file($tmpExample);
|
||||
$zip->addFileFromPath('sample.txt', $tmpExample);
|
||||
unlink($tmpExample);
|
||||
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(array('sample.txt'), $files);
|
||||
|
||||
$this->assertEquals(sha1_file($tmpDir . '/sample.txt'), $shaExample, "SHA-1 Mismatch Method: {$method}");
|
||||
}
|
||||
|
||||
public function testAddFileFromStream(): void
|
||||
{
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
@@ -433,7 +334,7 @@ class ZipStreamTest extends TestCase
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(array('sample.txt', 'test/sample.txt'), $files);
|
||||
$this->assertSame(['sample.txt', 'test' . DIRECTORY_SEPARATOR . 'sample.txt'], $files);
|
||||
|
||||
$this->assertStringEqualsFile(__FILE__, file_get_contents($tmpDir . '/sample.txt'));
|
||||
$this->assertStringEqualsFile($tmpDir . '/test/sample.txt', 'More Simple Sample Data');
|
||||
@@ -466,14 +367,14 @@ class ZipStreamTest extends TestCase
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
$zipArch = new \ZipArchive();
|
||||
$zipArch = new ZipArchive();
|
||||
$zipArch->open($tmp);
|
||||
|
||||
$sample1 = $zipArch->statName('sample.txt');
|
||||
$this->assertEquals(Method::STORE, $sample1['comp_method']);
|
||||
$this->assertSame(Method::STORE, $sample1['comp_method']);
|
||||
|
||||
$sample2 = $zipArch->statName('test/sample.txt');
|
||||
$this->assertEquals(Method::DEFLATE, $sample2['comp_method']);
|
||||
$this->assertSame(Method::DEFLATE, $sample2['comp_method']);
|
||||
|
||||
$zipArch->close();
|
||||
}
|
||||
@@ -500,7 +401,34 @@ class ZipStreamTest extends TestCase
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(array('sample.json'), $files);
|
||||
$this->assertSame(['sample.json'], $files);
|
||||
$this->assertStringEqualsFile($tmpDir . '/sample.json', $body);
|
||||
}
|
||||
|
||||
public function testAddFileFromPsr7StreamWithOutputToPsr7Stream(): void
|
||||
{
|
||||
[$tmp, $resource] = $this->getTmpFileStream();
|
||||
$psr7OutputStream = new Stream($resource);
|
||||
|
||||
$options = new ArchiveOptions();
|
||||
$options->setOutputStream($psr7OutputStream);
|
||||
|
||||
$zip = new ZipStream(null, $options);
|
||||
|
||||
$body = 'Sample String Data';
|
||||
$response = new Response(200, [], $body);
|
||||
|
||||
$fileOptions = new FileOptions();
|
||||
$fileOptions->setMethod(Method::STORE());
|
||||
|
||||
$zip->addFileFromPsr7Stream('sample.json', $response->getBody(), $fileOptions);
|
||||
$zip->finish();
|
||||
$psr7OutputStream->close();
|
||||
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
|
||||
$this->assertSame(['sample.json'], $files);
|
||||
$this->assertStringEqualsFile($tmpDir . '/sample.json', $body);
|
||||
}
|
||||
|
||||
@@ -529,7 +457,7 @@ class ZipStreamTest extends TestCase
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(array('sample.json'), $files);
|
||||
$this->assertSame(['sample.json'], $files);
|
||||
$this->assertStringEqualsFile($tmpDir . '/sample.json', $body);
|
||||
}
|
||||
|
||||
@@ -552,7 +480,7 @@ class ZipStreamTest extends TestCase
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertEquals(['sample.txt', 'test/sample.txt'], $files);
|
||||
$this->assertSame(['sample.txt', 'test' . DIRECTORY_SEPARATOR . 'sample.txt'], $files);
|
||||
|
||||
$this->assertStringEqualsFile($tmpDir . '/sample.txt', 'Sample String Data');
|
||||
$this->assertStringEqualsFile($tmpDir . '/test/sample.txt', 'More Simple Sample Data');
|
||||
@@ -562,7 +490,7 @@ class ZipStreamTest extends TestCase
|
||||
{
|
||||
// WORKAROUND (1/2): remove phpunit's output buffer in order to run test without any buffering
|
||||
ob_end_flush();
|
||||
$this->assertEquals(0, ob_get_level());
|
||||
$this->assertSame(0, ob_get_level());
|
||||
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
|
||||
@@ -583,4 +511,109 @@ class ZipStreamTest extends TestCase
|
||||
// WORKAROUND (2/2): add back output buffering so that PHPUnit doesn't complain that it is missing
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getTmpFileStream(): array
|
||||
{
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'zipstreamtest');
|
||||
$stream = fopen($tmp, 'wb+');
|
||||
|
||||
return [$tmp, $stream];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tmp
|
||||
* @return string
|
||||
*/
|
||||
protected function validateAndExtractZip($tmp): string
|
||||
{
|
||||
$tmpDir = $this->getTmpDir();
|
||||
|
||||
$zipArch = new ZipArchive();
|
||||
$res = $zipArch->open($tmp);
|
||||
|
||||
if ($res !== true) {
|
||||
$this->fail("Failed to open {$tmp}. Code: $res");
|
||||
|
||||
return $tmpDir;
|
||||
}
|
||||
|
||||
$this->assertSame(0, $zipArch->status);
|
||||
$this->assertSame(0, $zipArch->statusSys);
|
||||
|
||||
$zipArch->extractTo($tmpDir);
|
||||
$zipArch->close();
|
||||
|
||||
return $tmpDir;
|
||||
}
|
||||
|
||||
protected function getTmpDir(): string
|
||||
{
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'zipstreamtest');
|
||||
unlink($tmp);
|
||||
mkdir($tmp) or $this->fail('Failed to make directory');
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getRecursiveFileList(string $path): array
|
||||
{
|
||||
$data = [];
|
||||
$path = (string)realpath($path);
|
||||
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
||||
|
||||
$pathLen = strlen($path);
|
||||
foreach ($files as $file) {
|
||||
$filePath = $file->getRealPath();
|
||||
if (!is_dir($filePath)) {
|
||||
$data[] = substr($filePath, $pathLen + 1);
|
||||
}
|
||||
}
|
||||
|
||||
sort($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function addLargeFileFileFromPath($method, $zeroHeader, $zip64): void
|
||||
{
|
||||
[$tmp, $stream] = $this->getTmpFileStream();
|
||||
|
||||
$options = new ArchiveOptions();
|
||||
$options->setOutputStream($stream);
|
||||
$options->setLargeFileMethod($method);
|
||||
$options->setLargeFileSize(5);
|
||||
$options->setZeroHeader($zeroHeader);
|
||||
$options->setEnableZip64($zip64);
|
||||
|
||||
$zip = new ZipStream(null, $options);
|
||||
|
||||
[$tmpExample, $streamExample] = $this->getTmpFileStream();
|
||||
for ($i = 0; $i <= 10000; $i++) {
|
||||
fwrite($streamExample, sha1((string)$i));
|
||||
if ($i % 100 === 0) {
|
||||
fwrite($streamExample, "\n");
|
||||
}
|
||||
}
|
||||
fclose($streamExample);
|
||||
$shaExample = sha1_file($tmpExample);
|
||||
$zip->addFileFromPath('sample.txt', $tmpExample);
|
||||
unlink($tmpExample);
|
||||
|
||||
$zip->finish();
|
||||
fclose($stream);
|
||||
|
||||
$tmpDir = $this->validateAndExtractZip($tmp);
|
||||
|
||||
$files = $this->getRecursiveFileList($tmpDir);
|
||||
$this->assertSame(['sample.txt'], $files);
|
||||
|
||||
$this->assertSame(sha1_file($tmpDir . '/sample.txt'), $shaExample, "SHA-1 Mismatch Method: {$method}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BugHonorFileTimeTest;
|
||||
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZipStream\Option\{
|
||||
Archive,
|
||||
File
|
||||
};
|
||||
use ZipStream\ZipStream;
|
||||
|
||||
use function fopen;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ZipStream\Option\Archive;
|
||||
use ZipStream\Option\File;
|
||||
|
||||
use ZipStream\ZipStream;
|
||||
|
||||
/**
|
||||
* Asserts that specified last-modified timestamps are not overwritten when a
|
||||
* file is added
|
||||
|
||||
Reference in New Issue
Block a user