Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zip-a-folder

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zip-a-folder - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

27

lib/zip-a-folder.js
'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);
}
);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc