zip-a-folder
Advanced tools
Comparing version 0.0.6 to 0.0.7
'use strict'; | ||
var fs = require('fs'); | ||
var archiver = require('archiver'); | ||
var path = require('path'); | ||
@@ -18,16 +19,22 @@ class ZipAFolder { | ||
static zipFolder(srcFolder, zipFilePath, callback) { | ||
// folder double check | ||
fs.access(srcFolder, fs.constants.F_OK, (notExistingError) => { | ||
if (notExistingError) { | ||
callback(notExistingError); | ||
return callback(notExistingError); | ||
} | ||
var output = fs.createWriteStream(zipFilePath); | ||
var zipArchive = archiver('zip'); | ||
fs.access(path.dirname(zipFilePath), fs.constants.F_OK, (notExistingError) => { | ||
if (notExistingError) { | ||
return callback(notExistingError); | ||
} | ||
var output = fs.createWriteStream(zipFilePath); | ||
var zipArchive = archiver('zip'); | ||
output.on('close', function() { | ||
callback(); | ||
output.on('close', function() { | ||
callback(); | ||
}); | ||
zipArchive.pipe(output); | ||
zipArchive.directory(srcFolder, false); | ||
zipArchive.finalize(); | ||
}); | ||
zipArchive.pipe(output); | ||
zipArchive.directory(srcFolder, false); | ||
zipArchive.finalize(); | ||
}); | ||
@@ -37,2 +44,2 @@ } | ||
module.exports = ZipAFolder; | ||
module.exports = ZipAFolder; |
{ | ||
"name": "zip-a-folder", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Forked the idea of @sole to zip a complete folder into a zip file but now using promises", | ||
@@ -5,0 +5,0 @@ "main": "lib/zip-a-folder.js", |
@@ -66,1 +66,2 @@ [![NPM](https://nodei.co/npm/zip-a-folder.png)](https://nodei.co/npm/zip-a-folder/) | ||
* Special thanks to @sole for her initial work. | ||
* Thanks to YOONBYEONGIN |
@@ -1,41 +0,56 @@ | ||
'use strict'; | ||
"use strict"; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const zipafolder = require('../lib/zip-a-folder'); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const zipafolder = require("../lib/zip-a-folder"); | ||
describe('Zip-A-Folder Test', function() { | ||
let testasync = path.resolve(__dirname, 'testasync.zip'); | ||
let testcallback = path.resolve(__dirname, 'testcallback.zip'); | ||
describe("Zip-A-Folder Test", function() { | ||
let testasync = path.resolve(__dirname, "testasync.zip"); | ||
let testcallback = path.resolve(__dirname, "testcallback.zip"); | ||
let testnotexisting = path.resolve(__dirname, "/notexisting/testcallback.zip"); | ||
beforeAll(() => { | ||
if (fs.existsSync(testasync)) { | ||
fs.unlinkSync(testasync); | ||
} | ||
if (fs.existsSync(testcallback)) { | ||
fs.unlinkSync(testcallback); | ||
} | ||
}); | ||
beforeAll(() => { | ||
if (fs.existsSync(testasync)) { | ||
fs.unlinkSync(testasync); | ||
} | ||
if (fs.existsSync(testcallback)) { | ||
fs.unlinkSync(testcallback); | ||
} | ||
}); | ||
it('ASYNC: Zip test folder', async function() { | ||
expect.assertions(1); | ||
await zipafolder.zip(path.resolve(__dirname, 'data/'), testasync); | ||
it("ASYNC: Zip test folder", async function() { | ||
expect.assertions(1); | ||
await zipafolder.zip(path.resolve(__dirname, "data/"), testasync); | ||
expect(fs.existsSync(testasync)).toBe(true); | ||
}); | ||
expect(fs.existsSync(testasync)).toBe(true); | ||
}); | ||
it('ASYNC: Zip test folder failing', async function() { | ||
expect.assertions(1); | ||
try { | ||
await zipafolder.zip(path.resolve(__dirname, 'notexisting/'), testasync); | ||
} catch (e) { | ||
expect(e.message).toMatch(/no such file or directory/); | ||
} | ||
}); | ||
it("ASYNC: Zip test folder failing", async function() { | ||
expect.assertions(1); | ||
try { | ||
await zipafolder.zip(path.resolve(__dirname, "notexisting/"), testasync); | ||
} catch (e) { | ||
expect(e.message).toMatch(/no such file or directory/); | ||
} | ||
}); | ||
it('CALLBACK: Zip test folder', function() { | ||
zipafolder.zipFolder(path.resolve(__dirname, 'data/'), testcallback, err => { | ||
expect(fs.existsSync(testcallback)).toBe(true); | ||
}); | ||
}); | ||
it("ASYNC: Zip test folder into a zipfile in a notexisting folder", async function() { | ||
expect.assertions(1); | ||
try { | ||
await zipafolder.zip(path.resolve(__dirname, "data/"), testnotexisting); | ||
} catch (e) { | ||
expect(e.message).toMatch(/no such file or directory/); | ||
} | ||
}); | ||
it("CALLBACK: Zip test folder", function() { | ||
zipafolder.zipFolder( | ||
path.resolve(__dirname, "data/"), | ||
testcallback, | ||
() => { | ||
expect(fs.existsSync(testcallback)).toBe(true); | ||
} | ||
); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5900
84
67