Giter Club home page Giter Club logo

minimal-zip-file-creator's Introduction

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

minimal-zip-file-creator's People

Contributors

henbr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.