gromnan / s3-zip
Read partial zip on AWS S3 or HTTP
v1.0.0
2022-09-05 09:17 UTC
Requires
- php: >=7.4
- ext-zlib: *
- async-aws/s3: ^1.5
- psr/log: ^1.1|^2.0|^3.0
Requires (Dev)
- ext-zip: *
- symfony/phpunit-bridge: ^5.4|^6.0
This package is auto-updated.
Last update: 2024-11-06 18:00:03 UTC
README
Having a ZIP archive hosted on AWS S3 or an HTTP(S) server? How to list files in the archive or read only 1 file without downloading the whole archive?
This packages use the Range: bytes=%d-%d
header to download only the necessary chunks for listing files or reading a single file.
Installation
Use composer to install gromnan/s3-zip
from packagist.
composer require gromnan/s3-zip
Usage
use AsyncAws\S3\S3Client; use GromNaN\S3Zip\Archive; use GromNaN\S3Zip\Input\S3Input; use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpKernel\Log\Logger; $logger = new Logger(); $httpClient = HttpClient::create()->setLogger($logger); $s3 = new S3Client([/* AWS Config */], null, $httpClient, $logger); $filename = 's3://my-bucket/path/to/archive.zip'; $input = new S3Input($s3, $filename); $input->setLogger($logger); $archive = new Archive($input); // Get the list for file names in the archive var_dump($archive->getFileNames()); // Downloads and extracts the contents of a single file echo $archive->getFile('path/to/file/in/archive.txt')->getContents();
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.