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

littlezip

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

littlezip

Extremely simple .zip file creation with no dependencies

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

littlezip

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

This is not entirely 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, 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 OK if you are creating a .zip that is actually an .xlsx, .apk or .xpi file, for example.

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 littlezip

Usage

The library exposes a single function, createZip.

import { createZip } from 'littlezip'; 

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.

Keywords

FAQs

Package last updated on 13 Mar 2024

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