Skip to content

Instantly share code, notes, and snippets.

@burt202
Created December 17, 2015 13:44
Show Gist options
  • Save burt202/9a15d3a3805507a4e27d to your computer and use it in GitHub Desktop.
Save burt202/9a15d3a3805507a4e27d to your computer and use it in GitHub Desktop.
Parsing Zip Contents
var unzip = require("unzip");
var fs = require("fs");
var through = require("through2");
var htmlFiles = [];
var manifestContents = null;
fs.createReadStream("demo.zip")
.pipe(unzip.Parse())
.on("entry", function (entry) {
var fileName = entry.path;
var type = entry.type;
var ext = fileName.substr(fileName.lastIndexOf(".") + 1);
if (fileName === "manifest.json") {
entry.pipe(through.obj(function (contents) {
manifestContents = JSON.parse(contents);
}))
}
if (type === "File" && ext === "html") {
htmlFiles.push(fileName)
}
entry.autodrain();
})
.on("close", function () {
console.log(manifestContents);
console.log(htmlFiles);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment