DanielHindi/aws-s3-zipper

example for streamZipDataTo

Closed this issue · 4 comments

Hello,

it would be very nice to have an example for this function as i don't quite get how to use it.
I want to zip a folder from s3 and stream it back to s3 without writing to the disk. Any suggestion how to accomplish this? What kind of object does the param pipe expect?

Thanks in advance,
Simon

Currently the code stacks functions on top of each other thus serializing to a file before uploading. The main reason for this is because we dont know how big these files can be as well as the memory needed on the server.

However, this doesnt mean it cannot be done. You can change the stream from a file stream to a memory stream then pipe it back. You would need to test that aws-sdk and archiver can deal with memory streams

Hey again, thanks for the reply. Turns out you can use the pipe option to pipe the data through a passthrough transformed stream directly back to s3.(https://nodejs.org/api/stream.html#stream_class_stream_passthrough). Works like a charm. I can post a code example if someone needs help.

Awesome! Thanks for the update

How can this work in Express? Can't seem to make it work:

router.get('/', function (request, response) {
      zip.streamZipDataTo({
        folderName: 'folder',
        pipe: response
      })
)}