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

minimal-zip-file-creator

v0.1.1

Published

A small library for creating uncompressed ZIP files

Downloads

8

Readme

Minimal ZIP file creator library

This is an ES6 library containing the bare essentials for creating uncompressed ZIP files. The use case is mostly for when dealing with a lot small files or already compressed files, like images. The library can be used both in browsers and Node.js.

Features

  • Small (2.6 KiB minified, 1.1 KiB compressed)
  • No dependencies
  • Fast

Example

import { createZip } from "minimal-zip-file-creator";
import { saveAs } from "file-saver";

const zip = createZip([
  {
    name: "small_image.gif",
    content: new Uint8Array([
        71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 0, 255, 0, 44, 0, 0, 0, 0, 1, 0, 1,
        0, 0, 2, 0, 59,
      ]),
  },
  {
    name: "folder/hello.txt",
    content: "Hello world!",
  },
  {
    name: "folder/old_hello.txt",
    content: "Hello world!",
    date: new Date("1980-01-01")
  },
]);

saveAs(new Blob([zip]), "example.zip");

API

createZip(files)

Parameters

  • files: Array of objects containing the data of the files to be added to the ZIP file. The object should contain the following fields:
    • name: Name of the file. If an UTF-8 character is detected the UTF-8 storage mode will be automatically enabled. Folders can be added using the following syntax: "folder1/folder2/filename".
    • content: File content. This can be a String, Uint8Array or ArrayBuffer. String content will be encoded using UTF-8 encoding.
    • date: This field is optional and is used to specify the "last modified date" stored along the file in the ZIP. If omitted the current date will be used instead. This can be either a Date object or a number, specifying milliseconds since epoch.

Return value

An ArrayBuffer containing the ZIP file content.

Building

bun dist

Performance

See benchmark for the source code of this benchmark.

Chrome (120.0.6099.109)

benchmark                     time (avg)             (min … max)
----------------------------------------------------------------
minimal-zip-file-creator  128.56 ms/iter   (122.5 ms … 131.9 ms)
jzip                      457.46 ms/iter   (454.7 ms … 459.5 ms)

Firefox (119.0.1)

benchmark                     time (avg)             (min … max)
----------------------------------------------------------------
minimal-zip-file-creator  195.62 ms/iter       (192 ms … 204 ms)
jzip                         270 ms/iter       (259 ms … 291 ms)

Bun (1.0.18)

benchmark                     time (avg)             (min … max)
----------------------------------------------------------------
minimal-zip-file-creator   50.55 ms/iter   (48.24 ms … 79.98 ms)
jzip                      189.11 ms/iter  (185.1 ms … 216.73 ms)
archiver                   55.94 ms/iter   (47.46 ms … 88.53 ms)

References

License

See the LICENSE file