1.0.2 • Published 6 months ago

@shgysk8zer0/squish v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@shgysk8zer0/squish

Tiny JS compression/decompression library using CompressionStream

CodeQL Node CI Lint Code Base

GitHub license GitHub last commit GitHub release GitHub Sponsors

npm node-current npm bundle size gzipped npm

GitHub followers GitHub forks GitHub stars Twitter Follow

Donate using Liberapay


Efficient Data Compression and Decompression

Squish is a tiny JavaScript library that provides functionalities for efficient data compression and decompression. It supports various input and output formats, making it a versatile tool for optimizing data transmission and storage.

Features

  • Highly Compressed: The library itself is minified and compressed to an exceptionally small size, minimizing its footprint in your project.
  • Versatile Input: Accepts a wide range of input data types, including ReadableStream, ArrayBuffer, Uint8Array, Blob, Response, Request, and even strings.
  • Compression Algorithms: Supports both gzip and deflate compression algorithms, providing flexibility for different use cases.
  • Decompression: Decompresses data compressed with gzip and deflate algorithms.
  • Rich Output Formats: Offers a variety of output formats, including blob, stream, response, buffer, bytes, hex, base64, base64url, url, and text.

Installation

You can install the library using npm or by importing from a CDN such as unpkg.com:

npm install `@shgysk8zer0/squish`

or with a <script type="importmap">

<script type="importmap">
  {
    "imports": {
      "@shgysk8zer0/squish": "https://unpkg.com/@shgysk8zer0/squish@1.0.0/squish.min.js"
    }
  }
</script>

Usage

The library provides several functions for compression and decompression:

  • compress(data, options): Compresses the given data using the specified options.
  • decompress(data, options): Decompresses the given data using the specified options.
  • gzip(data, options): Compresses the data using the gzip algorithm.
  • gunzip(data, options): Decompresses the data compressed with gzip.
  • deflate(data, options): Compresses the data using the deflate algorithm.
  • inflate(data, options): Decompresses the data compressed with deflate.

Usage Example

Basic usage

import { gzip, gunzip } from '@shgysk8zer0/squish';

const compressed = await gzip('Hello, World!');
const decompressed = await gunzip(compressed, { output: 'text' });

Node usage (CJS - ESM also supported)

const { inflate } = require('@shgysk8zer0/squish');
const { readFile } = require('node:js');

async function sendFile(file) {
  const buffer = readFile(file);
  const compressed = await inflate(buffer);
  
  return new Response(compressed);
}

Requirements

This library requires many new features that are not yet wideley supported. A polyfill is provided in node, but you may want to proved your own for certain usages in browsers.

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago