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-dir

v2.0.0

Published

Zips up directories into buffers or saves zipped files to disk

Downloads

261,417

Readme

zip-dir

Zips up a directory and saves the zip to disk or returns as a buffer.

Build Status Build Status

install

$ npm install zip-dir

example

var zipdir = require('zip-dir');

// `buffer` is the buffer of the zipped file
var buffer = await zipdir('/path/to/be/zipped');

zipdir('/path/to/be/zipped', function (err, buffer) {
  // `buffer` is the buffer of the zipped file
});

zipdir('/path/to/be/zipped', { saveTo: '~/myzip.zip' }, function (err, buffer) {
  // `buffer` is the buffer of the zipped file
  // And the buffer was saved to `~/myzip.zip`
});

// Use a filter option to prevent zipping other zip files!
// Keep in mind you have to allow a directory to descend into!
zipdir('/path/to/be/zipped', { filter: (path, stat) => !/\.zip$/.test(path) }, function (err, buffer) {
  
});

// Use an `each` option to call a function everytime a file is added, and receives the path
zipdir('/path/to/be/zipped', { each: path => console.log(p, "added!"), function (err, buffer) {

});
  

methods

var zipdir = require('zip-dir');

zipdir(dirPath, [options], [callback]) : [Promise]

Zips up dirPath recursively preserving directory structure and returns the compressed buffer on success. If the callback function is supplied, it will be called with (error, buffer) once the zipdir function is done. If not, the buffer or an error can be obtained from the returned promise. The callback and the promise are mutually exclusive. If options defined with a saveTo path, then the callback and promise will be delayed until the buffer has also been saved to disk.

Options

  • saveTo A path to save the buffer to.
  • filter A function that is called for all items to determine whether or not they should be added to the zip buffer. Function is called with the fullPath and a stats object (fs.Stats). Return true to add the item; false otherwise. To include files within directories, directories must also pass this filter.
  • each A function that is called everytime a file or directory is added to the zip.

TODO

  • Add an option to not add empty directories if there are no valid children inside

license

MIT