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

node-native-zip2

v1.0.0

Published

A ZIP library without external dependencies

Downloads

1,082

Readme

This project has been abandoned in favor of node-archiver

If you're in need of a non-binary ZIP library for node.js, I'd like to redirect you to node-archiver.

node-native-zip

All the current ZIP solutions for node.js are wrappers around existing zip executables, spawning on demand. To all of you who rather have a native implementation of zip'ing in javascript there is node-native-zip. This package works with Buffer objects, which allows you to do complex in-memory stuff with the least amount of overhead.

It has been inspired by JSZip.

How to install

Via NPM:

npm install node-native-zip

Via GIT:

git clone git://github.com/janjongboom/node-native-zip.git

How to use

There are two ways to feed files into a new .zip file. Either by adding Buffer objects, or by adding an array of files.

Adding Buffer objects

    var fs = require("fs");
    var zip = require("node-native-zip");
    
    var archive = new zip();
    
    archive.add("hello.txt", new Buffer("Hello world", "utf8"));
    
    var buffer = archive.toBuffer();
    fs.writeFile("./test1.zip", buffer, function () {
        console.log("Finished");
    });

Adding files from the file system

    var fs = require("fs");
    var zip = require("node-native-zip");
    
    var archive = new zip();
    
    archive.addFiles([ 
        { name: "moehah.txt", path: "./test/moehah.txt" },
        { name: "images/suz.jpg", path: "./test/images.jpg" }
    ], function (err) {
        if (err) return console.log("err while adding files", err);
        
        var buff = archive.toBuffer();
        
        fs.writeFile("./test2.zip", buff, function () {
            console.log("Finished");
        });
    });

API Reference

There are three API methods:

  • add(name, data), the 'name' is the name within the .zip file. To create a folder structure, add '/'
  • addFiles(files, callback), where files is an array containing objects in the form { name: "name/in/zip.file", path: "file-system.path" }. Callback is a function that takes 1 parameter 'err' which indicates whether an error occured.
  • toBuffer(), creates a new buffer and writes the zip file to it

Compression?

The library currently doesn't do any compression. It stores the files via STORE. Main reason is that the compression call is synchronous at the moment, so the thread will block during compression, something to avoid. However, it is possible to add compression methods by implementing the following interface.

    module.exports = (function () {
        return {
            indicator : [ 0x00, 0x00 ],
            compress : function (content) {
                // content is a Buffer object.
                // you have to return a new Buffer too.
            }
        };
    }());

The indicator is an array consisting of two bytes indicating the compression technology. For example: [ 0x00, 0x00] is STORE, [ 0x08, 0x00] is DEFLATE.

The compress function is a method that transforms an incoming Buffer into a new one.

The easiest to implement is probably deflate, because there is a sample in JSZip. You will only need to change the inner workings from string-based to Buffer-based.

Unzipping

Unzipping is more complex because of all the different compression algorithms that you may encounter in the wild. So it's not covered. Use existing libraries for that.