TIL unzipping a file in node using zlib
POSTED ON:
TAGS: node compression automation
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:
-
fetch the newest files (in
.gz
format) on AWS S3 -
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`)
Related TILs
Tagged: node