Skip to content

Stream a file chunk by chunk #178

Answered by maennchen
vincentLock21 asked this question in Q&A
Discussion options

You must be logged in to vote

It should probably be possible to implement a custom class implementing PSR7 StreamInterface to do this.

EDIT:

This could work something like that (completely untested pseudo code):

use Psr7\AppendStream;
use Psr7\Utils;

$zip = new ZipStream('test.zip', $options);

foreach ($s3keys as $key => $value) {
  $fileName = $value;

  // $chunks = get chunks from S3;

  $fileStream = new AppendStream(array_map(function($chunk) using($bucket, $key, $value) {
    $path = sprintf('s3://%s/%s/%s/%s', $bucket, $key, $chunk->getChunk(), basename($value));

    return Utils::streamFor(openssl_decrypt(fopen($path, 'rb'), /* ... */));
  }, $chunks));

  $zip->addFileFromPsr7Stream($fileName, $fileStream)…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@dudz94
Comment options

@maennchen
Comment options

@vincentLock21
Comment options

@maennchen
Comment options

@vincentLock21
Comment options

Answer selected by maennchen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants