New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

littlezipper

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

littlezipper

Extremely simple .zip file creation with no dependencies

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.3K
increased by26.95%
Maintainers
0
Weekly downloads
 
Created
Source

littlezipper

This project uses the CompressionStream API — supported by all recent browsers, Node and Deno — to create .zip files.

This is not wholly trivial since, a little frustratingly, CompressionStream can natively produce .gz format data but not .zip. Thus, we pick out both the deflated data and the CRC from the .gz stream, and write them into a .zip file instead.

We don't actually have to implement any compression in JavaScript, so the library is fast and small.

Where CompressionStream is not available, we fall back to producing uncompressed .zip files (and calculate the CRC in heavily-optimized JavaScript). This may be acceptable if you are creating a .zip that is actually something else, such as an .xlsx, .apk or .xpi.

The library is currently suitable for small- and medium-sized files, since it briefly requires just over 2x the total uncompressed size of your files in memory. That's because you pass it an array of files data, and for the .zip output it allocates a Uint8Array backed by a worst-case ArrayBuffer, which is the size of all the uncompressed data plus a little more for headers.

Potential future improvements could include implementing a TransformStream instead, which could enable smaller memory use and larger file sizes. However, the .zip format annoyingly puts the CRC and compressed data size before the compressed data, which limits opportunities for memory saving.

Installation

npm install littlezipper

TypeScript types are included.

Usage

The library exposes a single function, createZip.

import { createZip } from 'littlezipper'; 

const zip = await createZip([
  { path: 'test.txt', data: 'This is a test', lastModified: new Date('2020-01-01T00:00:00') },
  { path: 'test.bin', data: new Uint8Array([1, 2, 3]) },
]);

The first argument to createZip is an array of file entries. Each entry must have path (string) and data (string, Uint8Array or ArrayBuffer) keys, and may have a lastModified (Date) key, which otherwise defaults to the current date and time.

The optional second argument defines whether we attempt to deflate the data (default: true). If false, the resulting .zip file will be as large as the input data plus a few bytes for headers.

License

Apache License, Version 2.0.

Keywords

FAQs

Package last updated on 04 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc