Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
/ s3-zip Public

Read partial ZIP on S3 (PHP)

Notifications You must be signed in to change notification settings

GromNaN/s3-zip

Repository files navigation

Partial ZIP Reader

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.

License

MIT

References