s3-zip
Download selected files from an Amazon S3 bucket as a zip file.
Install
npm install s3-zip
AWS Configuration
Refer to the AWS SDK for authenticating to AWS prior to using this plugin.
Usage
Zip specific files
const fs = const join = joinconst s3Zip = const region = 'bucket-region'const bucket = 'name-of-s3-bucket'const folder = 'name-of-bucket-folder/'const file1 = 'Image A.png'const file2 = 'Image B.png'const file3 = 'Image C.png'const file4 = 'Image D.png' const output = fs s3Zip archive region: region bucket: bucket folder file1 file2 file3 file4
You can also pass a custom S3 client. For example if you want to zip files from a S3 compatible storage:
const aws = const s3Client = signatureVersion: 'v4' s3ForcePathStyle: 'true' endpoint: 'http://localhost:9000' s3Zip archive s3: s3Client bucket: bucket folder file1 file2
Zip files with AWS Lambda
Example of s3-zip in combination with AWS Lambda.
Zip a whole bucket folder
const fs = const join = joinconst AWS = const s3Zip = const XmlStream = const region = 'bucket-region'const bucket = 'name-of-s3-bucket'const folder = 'name-of-bucket-folder/'const s3 = region: region const params = Bucket: bucket Prefix: folder const filesArray = const files = s3const xml = filesxmlxml xml { console const output = fs s3Zip archive region: region bucket: bucket preserveFolderStructure: true folder files }
Tar format support
s3Zip archive region: region bucket: bucket folder file1 file2
Zip a file with protected password
s3Zip archive region: region bucket: bucket folder file1 file2
Archiver options
We use archiver to create archives. To pass your options to it, use setArchiverOptions
method:
s3Zip archive region: region bucket: bucket folder file1 file2
Organize your archive with custom paths and permissions
You can pass an array of objects with type EntryData to organize your archive.
const files = 'flower.jpg' 'road.jpg'const archiveFiles = name: 'newFolder/flower.jpg' /* _rw_______ */ name: 'road.jpg' mode: ;s3Ziparchive region: region bucket: bucket folder files archiveFiles
Using with ExpressJS
s3-zip
works with any framework which leverages on NodeJS Streams including ExpressJS.
const s3Zip = app
Above should stream out the file in the response of the request.
Debug mode
Enable debug mode to see the logs:
s3Ziparchive region: region bucket: bucket debug: true folder files
Testing
Tests are written in Node Tap, run them like this:
npm t
If you would like a more fancy coverage report:
npm run coverage