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 1.1.0 to 1.1.1

44

dist/test/tests-ZipAFolder.js

@@ -5,2 +5,3 @@ 'use strict';

const fs = require("fs");
const rimraf = require("rimraf");
const path = require("path");

@@ -22,19 +23,6 @@ const ZipAFolder_1 = require("../lib/ZipAFolder");

beforeAll(() => {
deleteFile(testZIP);
deleteFile(testUNCOMPRESSEDZIP);
deleteFile(testMEDIUMZIP);
deleteFile(testSMALLZIP);
deleteFile(testSameDirectoryZIP);
deleteFile(testTAR);
deleteFile(testUNCOMPRESSEDTAR);
deleteFile(testMEDIUMTAR);
deleteFile(testSMALLTAR);
deleteFile(testSameDirectoryTAR);
rimraf.sync('test/*.tgz');
rimraf.sync('test/*.tar');
rimraf.sync('test/*.zip');
});
function deleteFile(file) {
try {
fs.unlinkSync(file);
}
catch (_) { }
}
it('ZIP test folder and zip target in same directory should throw an error', async () => {

@@ -60,3 +48,3 @@ await expect(ZipAFolder_1.ZipAFolder.zip(path.resolve(__dirname, 'data/'), testSameDirectoryZIP)).rejects.toThrow(/Source and target folder must be different./);

it('ZIP test folder direct via constant', async () => {
await ZipAFolder_1.zip(path.resolve(__dirname, 'data/'), testZIP);
await (0, ZipAFolder_1.zip)(path.resolve(__dirname, 'data/'), testZIP);
expect(fs.existsSync(testZIP)).toBe(true);

@@ -102,3 +90,3 @@ });

it('TGZ test folder direct via constant', async () => {
await ZipAFolder_1.tar(path.resolve(__dirname, 'data/'), testTAR);
await (0, ZipAFolder_1.tar)(path.resolve(__dirname, 'data/'), testTAR);
expect(fs.existsSync(testTAR)).toBe(true);

@@ -124,23 +112,27 @@ });

});
it('ZIP test custom writestream', async () => {
it('ZIP test custom writestream with zipfilepath empty string', async () => {
const customWS = fs.createWriteStream('test/123.zip');
await ZipAFolder_1.ZipAFolder.zip(path.resolve(__dirname, 'data/'), '', { customWriteStream: customWS });
expect(fs.existsSync(path.resolve(__dirname, '/test/data/123.zip'))).toBeTrue();
expect(fs.existsSync('test/123.zip')).toBeTrue();
});
it('ZIP test custom writestream', async () => {
it('ZIP test custom writestream with zipfilepath undefined', async () => {
const customWS = fs.createWriteStream('test/1234.zip');
await ZipAFolder_1.ZipAFolder.zip(path.resolve(__dirname, 'data/'), undefined, { customWriteStream: customWS });
expect(fs.existsSync(path.resolve(__dirname, '/test/data/1234.zip'))).toBeTrue();
expect(fs.existsSync('test/1234.zip')).toBeTrue();
});
it('TGZ test custom writestream', async () => {
it('TGZ test custom writestream with tarfilepath empty string', async () => {
const customWS = fs.createWriteStream('test/123.tgz');
await ZipAFolder_1.ZipAFolder.tar(path.resolve(__dirname, 'data/'), '', { customWriteStream: customWS });
expect(fs.existsSync(path.resolve(__dirname, '/test/data/123.tgz'))).toBeTrue();
expect(fs.existsSync('test/123.tgz')).toBeTrue();
});
it('TGZ test custom writestream', async () => {
it('TGZ test custom writestream with tarfilepath undefined', async () => {
const customWS = fs.createWriteStream('test/1234.tgz');
await ZipAFolder_1.ZipAFolder.tar(path.resolve(__dirname, 'data/'), undefined, { customWriteStream: customWS });
expect(fs.existsSync(path.resolve(__dirname, '/test/data/1234.tgz'))).toBeTrue();
expect(fs.existsSync('test/1234.tgz')).toBeTrue();
});
it.skip('Zip a very large folder ', async () => {
await ZipAFolder_1.ZipAFolder.zip(path.resolve(__dirname, 'largeFolder'), 'test/large.zip');
expect(fs.existsSync('test/large.zip')).toBeTrue();
});
});
//# sourceMappingURL=tests-ZipAFolder.js.map

@@ -13,2 +13,6 @@ 'use strict';

/**
* Options to pass in to zip a folder
* compression default is 'high'
*/
export type ZipAFolderOptions = {

@@ -20,2 +24,9 @@ compression?: COMPRESSION_LEVEL;

export class ZipAFolder {
/**
* Tars a given folder into a gzipped tar archive.
* If no zipAFolderOptions are passed in, the default compression level is high.
* @param srcFolder
* @param tarFilePath
* @param zipAFolderOptions
*/
static async tar(

@@ -30,6 +41,2 @@ srcFolder: string,

if (!tarFilePath && !zipAFolderOptions?.customWriteStream) {
throw new Error('You must either pass a target filename or a custom write stream');
}
if (o.compression === COMPRESSION_LEVEL.uncompressed) {

@@ -53,2 +60,9 @@ await ZipAFolder.compress({srcFolder, targetFilePath: tarFilePath, format: 'tar', zipAFolderOptions});

/**
* Zips a given folder into a zip archive.
* If no zipAFolderOptions are passed in, the default compression level is high.
* @param srcFolder
* @param tarFilePath
* @param zipAFolderOptions
*/
static async zip(

@@ -112,3 +126,3 @@ srcFolder: string,

await fs.promises.access(targetBasePath, fs.constants.R_OK | fs.constants.W_OK); //eslint-disable-line no-bitwise
} catch (e) {
} catch (e: any) {
throw new Error(`Permission error: ${e.message}`);

@@ -115,0 +129,0 @@ }

{
"name": "zip-a-folder",
"version": "1.1.0",
"version": "1.1.1",
"description": "Zip/Tar a complete folder into a zip/tgz file",

@@ -35,21 +35,21 @@ "main": "dist/lib/ZipAFolder.js",

"@types/archiver": "^5.1.1",
"@types/jest": "^26.0.24",
"@types/node": "^14.17.4",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.7",
"@types/rimraf": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"coveralls": "^3.1.1",
"eslint": "^7.30.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint": "^8.6.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"jest-extended": "^0.11.5",
"prettier": "^2.3.2",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.4.5",
"jest-extended": "^1.2.0",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.3",
"typescript": "^4.3.5"
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
},

@@ -56,0 +56,0 @@ "dependencies": {

@@ -53,2 +53,4 @@ [![NPM](https://nodei.co/npm/zip-a-folder.png)](https://nodei.co/npm/zip-a-folder/)

The default compression - level is 'high'.
```js

@@ -55,0 +57,0 @@ import { zip, COMPRESSION_LEVEL } from 'zip-a-folder';

@@ -29,2 +29,18 @@ 'use strict';

it('Called without a targetFilePath or a customWriteStream should throw an error', async () => {
await expect(zipafolder.zip(path.resolve(__dirname, 'data/'), undefined, {customWriteStream: undefined})).rejects.toThrow(
/You must either provide a target file path or a custom write stream to write to./
);
await expect(zipafolder.zip(path.resolve(__dirname, 'data/'), undefined)).rejects.toThrow(
/You must either provide a target file path or a custom write stream to write to./
);
await expect(zipafolder.tar(path.resolve(__dirname, 'data/'), undefined, {customWriteStream: undefined})).rejects.toThrow(
/You must either provide a target file path or a custom write stream to write to./
);
await expect(zipafolder.tar(path.resolve(__dirname, 'data/'), undefined)).rejects.toThrow(
/You must either provide a target file path or a custom write stream to write to./
);
});
it('ZIP test folder and zip target in same directory should throw an error', async () => {

@@ -66,3 +82,3 @@ await expect(zipafolder.zip(path.resolve(__dirname, 'data/'), testSameDirectoryZIP)).rejects.toThrow(

await zipafolder.zip(path.resolve(__dirname, 'notexisting/'), testZIP);
} catch (e) {
} catch (e: any) {
expect(e.message).toMatch(/no such file or directory/);

@@ -76,3 +92,3 @@ }

await zipafolder.zip(path.resolve(__dirname, 'data/'), testnotexistingZIP);
} catch (e) {
} catch (e: any) {
expect(e.message).toMatch(/no such file or directory/);

@@ -118,3 +134,3 @@ }

await zipafolder.tar(path.resolve(__dirname, 'notexisting/'), testTAR);
} catch (e) {
} catch (e: any) {
expect(e.message).toMatch(/no such file or directory/);

@@ -128,3 +144,3 @@ }

await zipafolder.tar(path.resolve(__dirname, 'data/'), testnotexistingTAR);
} catch (e) {
} catch (e: any) {
expect(e.message).toMatch(/no such file or directory/);

@@ -137,3 +153,3 @@ }

await zipafolder.zip(path.resolve(__dirname, 'data/'), '', {customWriteStream: customWS});
expect(fs.existsSync('test/123.zip')).toBeTrue();
expect(fs.existsSync('test/123.zip')).toBeTruthy();
});

@@ -144,3 +160,3 @@

await zipafolder.zip(path.resolve(__dirname, 'data/'), undefined, {customWriteStream: customWS});
expect(fs.existsSync('test/1234.zip')).toBeTrue();
expect(fs.existsSync('test/1234.zip')).toBeTruthy();
});

@@ -151,3 +167,3 @@

await zipafolder.tar(path.resolve(__dirname, 'data/'), '', {customWriteStream: customWS});
expect(fs.existsSync('test/123.tgz')).toBeTrue();
expect(fs.existsSync('test/123.tgz')).toBeTruthy();
});

@@ -158,4 +174,17 @@

await zipafolder.tar(path.resolve(__dirname, 'data/'), undefined, {customWriteStream: customWS});
expect(fs.existsSync('test/1234.tgz')).toBeTrue();
expect(fs.existsSync('test/1234.tgz')).toBeTruthy();
});
/**
* As this test is huuuuuuge I decided to only run it locally to check on github issue:
* https://github.com/maugenst/zip-a-folder/issues/32
* Preparation to run this test:
* * create a folder in test called 'largeFolder'
* * copy huge / tons of files into it
* * remove 'skip' and run the test
*/
it.skip('Zip a very large folder ', async () => {
await zipafolder.zip(path.resolve(__dirname, 'largeFolder'), 'test/large.zip');
expect(fs.existsSync('test/large.zip')).toBeTruthy();
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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