Today I Learned - Rocky Kev

TIL unzipping a file in node using zlib

POSTED ON:

TAGS:

I was working on a automation tool, and the serverless automation tool would grab a piece of content, then upload that content into my AWS S3 bucket as a .gz file.

.gz files are compressed files, zip files.

Since my application needs to read whatever is inside that .gz file, I had to figure out a way to simplify that.

Overall, my application would:

  1. fetch the newest files (in .gz format) on AWS S3

  2. unzip the file

That was done with the zlib library.

npm i zlib

const zlib = require('zlib');

function decompress(fileIn, fileOut) {
const unzip = zlib.createUnzip();

const input = fs.createReadStream(fileIn);
const output = fs.createWriteStream(fileOut);

input.pipe(unzip).pipe(output);
}

Then run it like this:

  decompress(item, `filename.json`)

Via:
https://pinoyitsolution.com/2019/05/22/how-to-unzip-multiple-gz-files-using-nodejs-and-zlib-on-windows-10/


Related TILs

Tagged:

TIL what is npm Script

Despite their high usage they are not particularly well optimized and add about 400ms of overhead. In this article we were able to bring that down to ~22ms.

TIL keywords in package.json

Today I learned what keywords are in a package.json file! It's a collection of keywords about a module. Keywords can help identify a package, related modules and software, and concepts.

TIL functional async/await

PLACEHOLDER