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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -