From bd65bb67e25a79b019d745b7262b2008ce2adb15 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 16 Nov 2016 01:59:39 +0100 Subject: incrementally verify denoms The denominations are not stored in a separate object store. --- node_modules/adm-zip/adm-zip.js | 93 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 11 deletions(-) (limited to 'node_modules/adm-zip/adm-zip.js') diff --git a/node_modules/adm-zip/adm-zip.js b/node_modules/adm-zip/adm-zip.js index 46595fc5d..26736bb02 100644 --- a/node_modules/adm-zip/adm-zip.js +++ b/node_modules/adm-zip/adm-zip.js @@ -186,7 +186,7 @@ module.exports = function(/*String*/input) { * * @param localPath */ - addLocalFile : function(/*String*/localPath, /*String*/zipPath) { + addLocalFile : function(/*String*/localPath, /*String*/zipPath, /*String*/zipName) { if (fs.existsSync(localPath)) { if(zipPath){ zipPath=zipPath.split("\\").join("/"); @@ -197,8 +197,12 @@ module.exports = function(/*String*/input) { zipPath=""; } var p = localPath.split("\\").join("/").split("/").pop(); - - this.addFile(zipPath+p, fs.readFileSync(localPath), "", 0) + + if(zipName){ + this.addFile(zipPath+zipName, fs.readFileSync(localPath), "", 0) + }else{ + this.addFile(zipPath+p, fs.readFileSync(localPath), "", 0) + } } else { throw Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath); } @@ -208,8 +212,21 @@ module.exports = function(/*String*/input) { * Adds a local directory and all its nested files and directories to the archive * * @param localPath + * @param zipPath optional path inside zip + * @param filter optional RegExp or Function if files match will + * be included. */ - addLocalFolder : function(/*String*/localPath, /*String*/zipPath) { + addLocalFolder : function(/*String*/localPath, /*String*/zipPath, /*RegExp|Function*/filter) { + if (filter === undefined) { + filter = function() { return true; }; + } else if (filter instanceof RegExp) { + filter = function(filter) { + return function(filename) { + return filter.test(filename); + } + }(filter); + } + if(zipPath){ zipPath=zipPath.split("\\").join("/"); if(zipPath.charAt(zipPath.length - 1) != "/"){ @@ -219,6 +236,7 @@ module.exports = function(/*String*/input) { zipPath=""; } localPath = localPath.split("\\").join("/"); //windows fix + localPath = pth.normalize(localPath); if (localPath.charAt(localPath.length - 1) != "/") localPath += "/"; @@ -229,11 +247,13 @@ module.exports = function(/*String*/input) { if (items.length) { items.forEach(function(path) { - var p = path.split("\\").join("/").replace(localPath, ""); //windows fix - if (p.charAt(p.length - 1) !== "/") { - self.addFile(zipPath+p, fs.readFileSync(path), "", 0) - } else { - self.addFile(zipPath+p, new Buffer(0), "", 0) + var p = path.split("\\").join("/").replace( new RegExp(localPath, 'i'), ""); //windows fix + if (filter(p)) { + if (p.charAt(p.length - 1) !== "/") { + self.addFile(zipPath+p, fs.readFileSync(path), "", 0) + } else { + self.addFile(zipPath+p, new Buffer(0), "", 0) + } } }); } @@ -328,7 +348,7 @@ module.exports = function(/*String*/input) { var content = item.getData(); if (!content) throw Utils.Errors.CANT_EXTRACT_FILE; - if (fs.existsSync(targetPath) && !overwrite) { + if (fs.existsSync(target) && !overwrite) { throw Utils.Errors.CANT_OVERRIDE; } Utils.writeFileTo(target, content, overwrite); @@ -362,6 +382,56 @@ module.exports = function(/*String*/input) { }) }, + /** + * Asynchronous extractAllTo + * + * @param targetPath Target location + * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true. + * Default is FALSE + * @param callback + */ + extractAllToAsync : function(/*String*/targetPath, /*Boolean*/overwrite, /*Function*/callback) { + overwrite = overwrite || false; + if (!_zip) { + callback(new Error(Utils.Errors.NO_ZIP)); + return; + } + + var entries = _zip.entries; + var i = entries.length; + entries.forEach(function(entry) { + if(i <= 0) return; // Had an error already + + if (entry.isDirectory) { + Utils.makeDir(pth.resolve(targetPath, entry.entryName.toString())); + if(--i == 0) + callback(undefined); + return; + } + entry.getDataAsync(function(content) { + if(i <= 0) return; + if (!content) { + i = 0; + callback(new Error(Utils.Errors.CANT_EXTRACT_FILE + "2")); + return; + } + Utils.writeFileToAsync(pth.resolve(targetPath, entry.entryName.toString()), content, overwrite, function(succ) { + if(i <= 0) return; + + if(!succ) { + i = 0; + callback(new Error('Unable to write')); + return; + } + + if(--i == 0) + callback(undefined); + }); + + }); + }) + }, + /** * Writes the newly created zip file to disk at the specified location or if a zip was opened and no ``targetFileName`` is provided, it will overwrite the opened zip * @@ -383,7 +453,8 @@ module.exports = function(/*String*/input) { var zipData = _zip.compressToBuffer(); if (zipData) { - Utils.writeFileTo(targetFileName, zipData, true); + var ok = Utils.writeFileTo(targetFileName, zipData, true); + if (typeof callback == 'function') callback(!ok? new Error("failed"): null, ""); } }, -- cgit v1.2.3