diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-16 01:59:39 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-16 02:00:31 +0100 |
commit | bd65bb67e25a79b019d745b7262b2008ce2adb15 (patch) | |
tree | 89e1b032103a63737f1a703e6a943832ef261704 /node_modules/adm-zip/adm-zip.js | |
parent | f91466595b651721690133f58ab37f977539e95b (diff) |
incrementally verify denoms
The denominations are not stored in a separate object store.
Diffstat (limited to 'node_modules/adm-zip/adm-zip.js')
-rw-r--r-- | node_modules/adm-zip/adm-zip.js | 93 |
1 files changed, 82 insertions, 11 deletions
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);
@@ -363,6 +383,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
*
* @param targetFileName
@@ -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, "");
}
},
|