https://github.com/shgysk8zer0/squish
Tiny JS compression/decompression library using `CompressionStream`
https://github.com/shgysk8zer0/squish
compression deflate gzip js node
Last synced: 8 months ago
JSON representation
Tiny JS compression/decompression library using `CompressionStream`
- Host: GitHub
- URL: https://github.com/shgysk8zer0/squish
- Owner: shgysk8zer0
- License: mit
- Created: 2025-01-05T02:10:52.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-01-23T21:22:28.000Z (8 months ago)
- Last Synced: 2025-01-30T12:01:53.304Z (8 months ago)
- Topics: compression, deflate, gzip, js, node
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@shgysk8zer0/squish
- Size: 218 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# @shgysk8zer0/squish
Tiny JS compression/decompression library using [`CompressionStream`](https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API)
[](https://github.com/shgysk8zer0/squish/actions/workflows/codeql-analysis.yml)

[](https://github.com/shgysk8zer0/squish/blob/master/LICENSE)
[](https://github.com/shgysk8zer0/squish/commits/master)
[](https://github.com/shgysk8zer0/squish/releases)
[](https://github.com/sponsors/shgysk8zer0)[](https://www.npmjs.com/package/@shgysk8zer0/squish)


[](https://www.npmjs.com/package/@shgysk8zer0/squish)[](https://github.com/shgysk8zer0)


[](https://twitter.com/shgysk8zer0)[](https://liberapay.com/shgysk8zer0/donate "Donate using Liberapay")
- - -- [Code of Conduct](./.github/CODE_OF_CONDUCT.md)
- [Contributing](./.github/CONTRIBUTING.md)## 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`:
```bash
npm install `@shgysk8zer0/squish`
```
or with a `````html
<script type="importmap">
{
"imports": {
"@shgysk8zer0/squish": "https://unpkg.com/@shgysk8zer0/squish@1.0.0/squish.min.js"
}
}```
## 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
```js
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)
```js
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.- [`CompressionStream`](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
- [`DecompressionStream`](https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream)
- [`Unit8Array.prototype.toBase64`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64)
- [`Uint8Array.prototype.toHex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex)
- [`Response.prototype.bytes`](https://developer.mozilla.org/en-US/docs/Web/API/Response/bytes)