33 lines
835 B
ReStructuredText
Raw Normal View History

2023-07-15 10:16:32 +08:00
Stream Output
===============
Stream to S3 Bucket
---------------
.. code-block:: php
use Aws\S3\S3Client;
use Aws\Credentials\CredentialProvider;
2023-08-09 15:01:26 +08:00
use ZipStream\Option\Archive;
2023-07-15 10:16:32 +08:00
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');
2023-08-09 15:01:26 +08:00
$options = new Archive();
$options->setEnableZip64(false);
$options->setOutputStream($zipFile);
2023-07-15 10:16:32 +08:00
2023-08-09 15:01:26 +08:00
$zip = new ZipStream(null, $options);
$zip->addFile('file1.txt', 'File1 data');
$zip->addFile('file2.txt', 'File2 data');
2023-07-15 10:16:32 +08:00
$zip->finish();
2023-08-09 15:01:26 +08:00
fclose($zipFile);