npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zip-a-folder

v3.1.8

Published

Zip/Tar a complete folder or a glob list into a zip/tgz file

Downloads

773,886

Readme

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