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

v0.5.0

Published

Compresses files and directories into blocks of predetermined size

Downloads

9

Readme

zip-blocks v0.5.0

Interface to zip files in blocks of predetermined maximum size

Install

npm install zip-blocks

zip-blocks

Constructor

Pass an object to the constructor to specify settings. See example below.

The settings object can contain keys from among the following (default values are given):

{
  blockSize: 20,        // in MB
  compressionRatio: 1,  // no compression
  filesOnly: true,
  addOversize: true
}
  • filesOnly: If set to false, directories are included in the operation as well.
  • addOversize: If left at true, individual files/directories exceeding the maximum block size will be added to individual archives; for false, they will be skipped and an error event emitted listing oversized items.
  • compressionRatio: If the string 'exact' is provided for ratio, the sizes of the compressed files will be calculated (by zipping them into a temporary folder). Note that this is only available for filesOnly set to true, and will approximately double the duration of the operation. Otherwise, ratio should be a value from 0.01 to 1, inclusive, and is used to estimate the compressibility of the files when determining the maximum number of files per block. The default is 1, which is equivalent to no compression (e.g. for PNG, MP3, etc.). Note that setting the compression ratio to a numeric value will not affect the actual zip compression performance.

Methods

zipFilesInDir(inputDir, [outputDir], [name], [callback])

Adds all files at the root of inputDir to a set of zip archives. Each of the archives produced is smaller than or equal to the blockSize setting. (The original motivation was to zip a set of files into archives that can be individually sent as email attachments.) If no outputDir is provided, zip files are written to inputDir. name is used as the base name for the generated archives; defaults to the name of the input directory. callback does not receive any arguments.

zipIndividually(inputDir, [outputDir], [name], [callback])

Adds each file in inputDir to its own zip archive. If no outputDir is provided, zip files are written to inputDir. If name is omitted, the original filenames are used for the archives. filesOnly is the only applicable key in options. callback does not receive any arguments.

Events

Extends events.EventEmitter. Set an error callback with on('error', callback). The default error handler prints the error message and continues.

Example

const ZipBlocks = require('zip-blocks')
const options = {
    blockSize: 2,      // in MB
    filesOnly: false,  // include directories
}
const zip = new ZipBlocks(options)
const callback = function () { console.log('All done!') }

zip.on('error', function (err) { /* handdle error */ })

zip.zipFilesInDir('files/in', 'files/out', 'output_name', callback)

zip.zipIndividually('files/in', 'files/out', callback)