node.js - How can i read a json file in gzip? -
there archive format gzip. there json files. need each file in turn , , written in other gzip. realized need use standard library createreadstream , zlib.
well, following example https://nodejs.org/api/zlib.html#zlib_examples following process done single gzipped file:
var unzip = zlib.createunzip(); var fs = require('fs'); var inp = fs.createreadstream('input.json.gz'); var out = fs.createwritestream('output.json'); inp.pipe(unzip).pipe(out);
however if there multiple files within gzip, not sure how 1 go doing that. not find documentation , way found multiple files unzipped gzip file in node if tar'd first. process unzipping tar.gz in node can found here. following example, 1 this:
var unzip = zlib.createunzip(); var fs = require('fs'); var tar = require('tar-fs'); var inp = fs.createreadstream('input.tar.gz'); var out = './output'; // output directory inp.pipe(unzip).pipe(tar.extract(out));
Comments
Post a Comment