StreamOutput.rst 835 B

123456789101112131415161718192021222324252627282930313233
  1. Stream Output
  2. ===============
  3. Stream to S3 Bucket
  4. ---------------
  5. .. code-block:: php
  6. use Aws\S3\S3Client;
  7. use Aws\Credentials\CredentialProvider;
  8. use ZipStream\Option\Archive;
  9. use ZipStream\ZipStream;
  10. $bucket = 'your bucket name';
  11. $client = new S3Client([
  12. 'region' => 'your region',
  13. 'version' => 'latest',
  14. 'bucketName' => $bucket,
  15. 'credentials' => CredentialProvider::defaultProvider(),
  16. ]);
  17. $client->registerStreamWrapper();
  18. $zipFile = fopen("s3://$bucket/example.zip", 'w');
  19. $options = new Archive();
  20. $options->setEnableZip64(false);
  21. $options->setOutputStream($zipFile);
  22. $zip = new ZipStream(null, $options);
  23. $zip->addFile('file1.txt', 'File1 data');
  24. $zip->addFile('file2.txt', 'File2 data');
  25. $zip->finish();
  26. fclose($zipFile);