DEV Community 👩‍💻👨‍💻

Felipe Leao
Felipe Leao

Posted on

How to unzip .zip files from s3 bucket back to s3

The problem

  • Get an .zip file provided from s3 bucket and upload the extracted folder and its content back to s3 bucket

The solution

  • Built an npm package that gets an .zip file from s3 and create streams, with that you can do whatever you want with the extracted content.

  • You can check more and contribute to our package in: s3-zip-handler

built-in possibilities

  • Send extracted folder back to s3 bucket

import AWS from 'aws-sdk'
import s3ZipHandler, { IS3ZipFileParams } from 's3-zip-handler'

const s3Client = new AWS.S3({
...your s3 settings
})


const s3Config: IS3ZipFileParams = {
    s3Client,
    bucket: 'your-s3-bucket',
    key: 'your-s3-key/your-zip-file.zip',
    params: {
      ACL: 'public-read',
      ContentDisposition: 'inline'
    }
} 

const {
localPath, 
uploadedPath 
} = await s3ZipHandler.decompressToKeyFolderS3(s3Config)

// localPath = 'os-tmp/unzipped-xxxx/your-zip-file'
// uploadedPath  = 'your-s3-bucket/your-s3-key/your-zip-file'

Enter fullscreen mode Exit fullscreen mode
  • Manipulate locally the extracted folder
import s3ZipHandler from 's3-zip-handler'
import AWS from 'aws-sdk'

const s3Client = new AWS.S3({
    ...your s3 settings
})

const s3Config = {
    s3Client,
    bucket: 'your-s3-bucket',
    key: 'your-s3-key/your-zip-file.zip'
} 

const {
 localPath
 } = await s3ZipHandler.decompressLocal(s3Config, 'path-to-extract')

// localPath = 'path-to-extract/your-zip-file'


Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
brunosoares99 profile image
Bruno Soares

Nice, awesome project!

Collapse
felipeleao18 profile image
Felipe Leao Author

thanks!!!!

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.