Sorry, the diff of this file is not supported yet
| /* | ||
| * Theses tests check the library coverage of logical directories in zip files | ||
| * The library should always convert such directories to real ones to ensure | ||
| * an error free experince when unzipping these files to disk | ||
| */ | ||
| var zipper = require('./../main') | ||
| var expect = require('chai').expect; | ||
| describe("Logical to Real Directories Conversion", function() { | ||
| it('converts logical directories in an existing zip file (async)', function(done) { | ||
| zipper.unzip('./tests/assets/folders.zip', function(error, unzipped) { | ||
| expect(error).to.be.null; | ||
| expect(unzipped.lowLevel().files).to.include.keys('folder1/'); | ||
| expect(unzipped.lowLevel().files['folder1/'].dir).to.be.true; | ||
| done(); | ||
| }); | ||
| }); | ||
| it('converts logical directories in an existing zip file (sync)', function() { | ||
| var unzipped = zipper.sync.unzip('./tests/assets/folders.zip') | ||
| expect(unzipped.lowLevel().files).to.include.keys('folder1/'); | ||
| expect(unzipped.lowLevel().files['folder1/'].dir).to.be.true; | ||
| }); | ||
| it('converts logical directories in low-level added files', function() { | ||
| var unzipped = zipper.sync.unzip('./tests/assets/hello.zip'); | ||
| unzipped.lowLevel().file('logical/test.txt', 'logical'); | ||
| expect(unzipped.lowLevel().files).to.include.keys('logical/'); | ||
| expect(unzipped.lowLevel().files['logical/'].dir).to.be.true; | ||
| }); | ||
| }); |
+4
-0
@@ -0,1 +1,5 @@ | ||
| # v0.3.3 | ||
| Released 4/22/2016 | ||
| * Defaulted the `createFolders` options in JSZip to `true` everywhere to ensure the conversion of logical directories in zip files to real ones, thus avoiding errors in extracting. | ||
| # v0.3.2 | ||
@@ -2,0 +6,0 @@ Released 4/15/2016 |
+38
-4
@@ -9,2 +9,36 @@ var fs = require('graceful-fs'); | ||
| /* | ||
| * factory method to create jszip objects where 'createFolders' | ||
| * option is the default behavior everywhere | ||
| */ | ||
| JSZip.make = function(data, options) { | ||
| // augments the options object with a 'createFolders' option | ||
| function augment(_opts) { | ||
| var opts = _opts || {}; | ||
| opts.createFolders = opts.createFolders || true; | ||
| return opts; | ||
| } | ||
| var instance = new JSZip(data, augment(options)); | ||
| var originals = {}; | ||
| originals.load = instance.load; | ||
| originals.file = instance.file; | ||
| instance.load = function(data, options) { | ||
| return originals.load.call(instance, data, augment(options)); | ||
| }; | ||
| instance.file = function(name, data, options) { | ||
| if(!data) { | ||
| return originals.file.call(instance, name); | ||
| } | ||
| return originals.file.call(instance, name, data, augment(options)); | ||
| }; | ||
| return instance; | ||
| }; | ||
| /***************************************************************************************** | ||
@@ -152,3 +186,3 @@ ******************************** PRIVATE HELPER FUNCTIONS ******************************** | ||
| var zipped_obj = new JSZip(); | ||
| var zipped_obj = JSZip.make(); | ||
@@ -238,3 +272,3 @@ if (typeof entity === "string") { | ||
| var callback = _callback || function () { }; | ||
| var zipped_obj = new JSZip(); | ||
| var zipped_obj = JSZip.make(); | ||
@@ -284,3 +318,3 @@ if (typeof file === "string") { | ||
| var zipped_obj = new JSZip(); | ||
| var zipped_obj = JSZip.make(); | ||
@@ -337,3 +371,3 @@ if (typeof entity === "string") { | ||
| var zipped_obj = new JSZip(); | ||
| var zipped_obj = JSZip.make(); | ||
@@ -340,0 +374,0 @@ if (typeof file === "string") { |
+1
-1
| { | ||
| "name": "zip-local", | ||
| "version": "0.3.2", | ||
| "version": "0.3.3", | ||
| "description": "very simple zipping/uzipping of local files and directories in node.js", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
+40
-40
@@ -36,14 +36,14 @@ # zip-local | ||
| if(!error) { | ||
| zipped.compress(); // compress before exporting | ||
| if(!error) { | ||
| zipped.compress(); // compress before exporting | ||
| var buff = zipped.memory(); // get the zipped file as a Buffer | ||
| var buff = zipped.memory(); // get the zipped file as a Buffer | ||
| // or save the zipped file to disk | ||
| zipped.save("../package.zip", function(error) { | ||
| if(!error) { | ||
| console.log("saved successfully !"); | ||
| } | ||
| }); | ||
| } | ||
| // or save the zipped file to disk | ||
| zipped.save("../package.zip", function(error) { | ||
| if(!error) { | ||
| console.log("saved successfully !"); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
@@ -81,17 +81,17 @@ ``` | ||
| if(!error) { | ||
| // extract to the current working directory | ||
| unzipped.save(null, function() { }); | ||
| if(!error) { | ||
| // extract to the current working directory | ||
| unzipped.save(null, function() { }); | ||
| var unzippedfs = unzipped.memory(); | ||
| var unzippedfs = unzipped.memory(); | ||
| // print an array of file paths in the unzipped file | ||
| console.log(unzippedfs.contents()); // prints [ 'hello-world.cpp' ] | ||
| // print an array of file paths in the unzipped file | ||
| console.log(unzippedfs.contents()); // prints [ 'hello-world.cpp' ] | ||
| // read the file as text | ||
| var txt = unzippedfs.read("hello-world.cpp", 'text'); | ||
| // read the file as text | ||
| var txt = unzippedfs.read("hello-world.cpp", 'text'); | ||
| // or read it as Buffer | ||
| var buff = unzippedfs.read("hello-world.cpp", 'buffer'); | ||
| } | ||
| // or read it as Buffer | ||
| var buff = unzippedfs.read("hello-world.cpp", 'buffer'); | ||
| } | ||
| }); | ||
@@ -136,14 +136,14 @@ ``` | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| return; | ||
| } | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| return; | ||
| } | ||
| // cache a copy of the zipped file on the server | ||
| zipped.save("zipped_from" + socket.remoteAddress + ".zip", function(error) { | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| return; | ||
| } | ||
| }); | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| return; | ||
| } | ||
| }); | ||
@@ -170,6 +170,6 @@ // send the zipped file back to the client | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| return; | ||
| } | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| return; | ||
| } | ||
@@ -191,8 +191,8 @@ var unzippedFS = unzipped.memory(); | ||
| zipped.save("package.zip", function(error) { | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| } | ||
| else { | ||
| console.log("The file is scanned and cleaned of executables"); | ||
| } | ||
| if(error) { | ||
| console.log("ERROR: %s", error.message); | ||
| } | ||
| else { | ||
| console.log("The file is scanned and cleaned of executables"); | ||
| } | ||
| }); | ||
@@ -199,0 +199,0 @@ }); |
@@ -26,3 +26,3 @@ var fs = require('fs'); | ||
| var zipped = new JSZip(localMemory.T1ZippedBuffer); | ||
| var zipped = JSZip.make(localMemory.T1ZippedBuffer); | ||
@@ -64,3 +64,3 @@ expect(zipped.files).to.have.property("world/").with.property('dir', true) && | ||
| var zipped = new JSZip(data); | ||
| var zipped = JSZip.make(data); | ||
@@ -67,0 +67,0 @@ expect(zipped.files).to.have.property("world/").with.property('dir', true) && |
@@ -19,3 +19,3 @@ var fs = require('fs'); | ||
| var zipped = new JSZip(localMemory.T1ZippedBuffer); | ||
| var zipped = JSZip.make(localMemory.T1ZippedBuffer); | ||
@@ -46,3 +46,3 @@ expect(zipped.files).to.have.property("world/").with.property('dir', true) && | ||
| var zipped = new JSZip(data); | ||
| var zipped = JSZip.make(data); | ||
@@ -49,0 +49,0 @@ expect(zipped.files).to.have.property("world/").with.property('dir', true) && |
@@ -26,3 +26,3 @@ var fs = require('fs'); | ||
| var zipped = new JSZip(localMemory.T1ZippedBuffer); | ||
| var zipped = JSZip.make(localMemory.T1ZippedBuffer); | ||
@@ -61,3 +61,3 @@ expect(zipped.files).to.have.property("hello-world") && | ||
| var zipped = new JSZip(data); | ||
| var zipped = JSZip.make(data); | ||
@@ -89,3 +89,3 @@ expect(zipped.files).to.have.property("hello-world") && | ||
| var zipped = new JSZip(localMemory.T5ZippedBuffer); | ||
| var zipped = JSZip.make(localMemory.T5ZippedBuffer); | ||
@@ -92,0 +92,0 @@ expect(zipped.files).to.have.property("hello-world") && |
@@ -19,3 +19,3 @@ var fs = require('fs'); | ||
| var zipped = new JSZip(localMemory.T1ZippedBuffer); | ||
| var zipped = JSZip.make(localMemory.T1ZippedBuffer); | ||
@@ -43,3 +43,3 @@ expect(zipped.files).to.have.property("hello-world") && | ||
| var zipped = new JSZip(data); | ||
| var zipped = JSZip.make(data); | ||
@@ -64,3 +64,3 @@ expect(zipped.files).to.have.property("hello-world") && | ||
| var zipped = new JSZip(localMemory.T5ZippedBuffer); | ||
| var zipped = JSZip.make(localMemory.T5ZippedBuffer); | ||
@@ -67,0 +67,0 @@ expect(zipped.files).to.have.property("hello-world") && |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
53567
6.07%21
10.53%920
6.24%