3.1.7 • Published 12 months ago

zip-a-folder v3.1.7

Weekly downloads
21,426
License
MIT
Repository
github
Last release
12 months ago

NPM

CircleCI Codacy Badge Codacy Badge Known Vulnerabilities

zip-a-folder

Easy to use zip (or tar) a complete folder or a list of globs plain into a zip/tar/tgz file including compression ratio handling and custom write streams.

incompatible changes

  • Version 2 adds glob lists handling as a src. So please be aware that using globs intentionally breaks up the "create-a-zip/tar-file-from-a-folder" approach.
  • Version 3 adds the possibility to zip-a-folder to be usable either in commonjs or esm module environments.
  • Version 3.1 adds the possibility to specify target folder within a zip file. By default the structure within a zip file doesn't contain the src folder, but the files and folder underneath.

Basic Usage

Install via npm

npm install zip-a-folder

Creating a ZIP file

import { zip } from 'zip-a-folder';

class TestMe {

    static async main() {
        await zip('/path/to/the/folder', '/path/to/archive.zip');
    }
}

TestMe.main();

Creating a gzipped TAR file

import { tar } from 'zip-a-folder';

class TestMe {

    static async main() {
        await tar('/path/to/the/folder', '/path/to/archive.tgz');
    }
}

TestMe.main();

Compression handling

For the sake of easy use, supported compression levels are (by now): COMPRESSION_LEVEL.high, COMPRESSION_LEVEL.medium or COMPRESSION_LEVEL.uncompressed.

The default compression - level is high.

import { zip, COMPRESSION_LEVEL } from 'zip-a-folder';

class TestMe {

    static async main() {
        await zip('/path/to/the/folder', '/path/to/archive.zip', {compression: COMPRESSION_LEVEL.high});
    }
}

TestMe.main();

Custom writeStreams

You can now pipe output to any WriteStream (just pass WriteStream as a parameter).

To keep the existing api stable the 2nd parameter (targetFilePath) can now be either undefined or an empty string.

ATTENTION: customWriteStream is not checked. So it is up to the user to check on non-existing target folders or if the targetfolder equals to the sourcefolder (ending up in circularity).

import { zip, COMPRESSION_LEVEL } from 'zip-a-folder';
import { fs } from 'fs';

class TestMe {
    static async main() {
        const customWS = fs.createWriteStream('test/1234.zip');
        await zipafolder.zip(path.resolve(__dirname, 'data/'), undefined, {customWriteStream: customWS});    
    }
}

TestMe.main();

Glob handling

The first parameter can be either a path or a glob. Globs are separated by comma.

import {zip} from 'zip-a-folder';

class TestMe {

    static async main() {
        // zip all json into an archive
        await zip('**/*.json', '/path/to/archive.zip');
        // zip all json AND txt files into a second archive
        await zip('**/*.json, **/*.txt', '/path/to/archive2.zip');
    }
}

TestMe.main();

Destination path handling (>=3.1.x)

With passing a destination path to zip-a-folder options object you can define the target folder structure within the generated zip.

import {zip} from 'zip-a-folder';

class TestMe {

    static async main() {
        // zip all json into an archive
        await zip('data/', '/path/to/archive.zip', {destPath: 'data/'});
    }
}

TestMe.main();

Tests

Tests can be found in /test and run by jest. To run the tests call npm test.

Thanks

  • Special thanks to @sole for her initial work.
  • Thanks to YOONBYEONGIN
  • Thanks to Wunschik
  • Thanks to ratbeard
  • Thanks to Xotabu4
  • Thanks to dallenbaldwin
  • Thanks to wiralegawa
  • Thanks to karan-gaur
  • Thanks to malthe
@poolminer/bjspm@lrfmedia/lrfmedia_climy-app-common-codcodestore-cli@daysmart/frankenstack-clifrankenstack-clirocketcloudcatalysis-clipublish-cdk-assets@everything-registry/sub-chunk-3233@kasif-apps/plugin-compilerreact-native-air-update@wyswill/wys_clitamnt-imagetangle-cli-alphatangle-cli-testwincc-cliweb_auto_codeceptjswp-plugin-helperxkite-corespdkspoodev-clisussdkvoroniyx-dbtoolsvkma-alpha@upsoft/patchkit-launcher2-runtime-base@clowzed/sero@contrail/cli@domoskanonos/workboy@botonic/clijsview-scratch-to-jskibo-import-export-utilitykindle-gideonlameboy@electronforconstruct/clisrn-clispurtcartstitch-cli-toolterrac@atomist/sdm-pack-drift@atomist/sdm-pack-aspect@awsless/awsless@0xengine/xmlrpc@abcnews/shrink-ray@aaneto/lambda-ts-cli@differentialhq/cli@davidwl/pluggable-widgets-toolsyarle-evernote-to-mdyoui-project-graphwbdlwebgme-taxonomytsk-jsuniform_structure_filezeta-quickzip-quasar-build@filen/desktop@greenwood/plugin-adapter-netlify@gveditor/sdk@haravan/cli@hanakla/cep-app-scripts@fowapps/fow-cli@fm2/sdk@flit/publish-cdk-assets@glueit/learn-infrastructure@kupihao/mongo-connection@mariop1010/update-wordpress-plugin-or-theme@nesvet/conveyer@ezavalishin/vk-miniapps-deploy-group@mendix/pluggable-widgets-tools@hisorange/housekeeper@punks/ci@sap/abap-deploy@sap/adp-common@sap/generator-adaptation-project-deployment@redoute/deploy@redcup/vk-mini-cli@orseki/gcloud-sample@owlworks/composer-extension-bot-publish@sportsdigita/ddcomponents-cli@spurtcommerce/climitene-photo-fetchermidrun-climern-crud-generatorn4-simple-buildpack-hash-filesorgnote-clioswaldcryptoss-web-deployose-modules-clinyc-build-helperoffline-websitenv-node-projectpatchkit-launcher2-basepatchkit-launcher2-runtime-basepalico-appsce-generate-reposcorm-multi-sco-manifestsci-rest-clientsadaivnitrodeploy
3.1.7

12 months ago

3.1.6

1 year ago

3.1.5

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

7 years ago

0.0.5

7 years ago