jdwil/zip-stream
Composer 安装命令:
composer require jdwil/zip-stream
包简介
README 文档
README
This library is for generating large zip files with a low memory footprint. The contents of the zip file are never stored in memory at once. Everything is written using streams. This library is for writing zip files only and has no reading capabilities.
License
MIT License
Getting Started
The only requirements are PHP 7.0+ and the zlib extension (almost always enabled).
Installing
composer require jdwil/zip-stream
Running tests
./vendor/bin/phpspec run
Examples
Basic Usage
$zipStream = ZipStream::forFile('/path/to/file.zip');
// Add a file from disk
$zipStream->addFileFromDisk('foo.txt', '/path/to/foo.txt');
// Add a file from a stream
$stream = ReadStream::forFile('/path/to/bar.txt');
$zipStream->addFileFromStream('bar.txt', $stream);
// Add arbirary data
$zipStream->addFile('baz.txt', 'some arbitrary text');
// Always close the Zip Stream
$zipStream->close();
Dealing with huge data sets
$zipStream = ZipStream::forFile('/path/to/file.zip');
$zipStream->beginFile('foo.txt');
while ($data = $somePdoStatement->fetch()) {
$zipStream->addFilePart(implode(',', $data));
}
$zipStream->endFile();
$zipStream->close();
Stream a ZIP file directly to the user
The file is sent as it is being built, so the download begins immediately for the user.
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="foo.zip"');
header('Content-Transfer-Encoding: binary');
$zipStream = ZipStream::forFile('php://output');
// Build your zip file
$zipStream->close();
Authors
JD Williams me@jdwilliams.xyz
统计信息
- 总下载量: 6.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-14