Search code examples
node.jszlibunzip

How to unzip an archive using zlib in Node.js?


How can I use zlib to unzip an archive in Node.js?

I'm using this in a Lambda function on AWS. I'm pulling down a ziped file that gets created from CodePipeline. Once I download it I can access it's Body property which seems to be a Buffer. How do I extract the files in that zip to the local "tmp" directory?

I'd like to stick with the zlib so I can use the AWS console to edit the code, zlib is installed on Lambda environments by default.


Solution

  • zlib by itself does not process .zip files. You need something like libarchive or libzip for that. (Both of those use zlib for the core compression, decompression, and CRC-32 calculation.)

    I looks like they are both part of the Amazon Linux AMI.