Created
December 17, 2015 13:44
-
-
Save burt202/9a15d3a3805507a4e27d to your computer and use it in GitHub Desktop.
Parsing Zip Contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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