npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gzip-utils

v1.0.0

Published

Gzip and Gunzip text, File, Blob, Uint8Array or stream using native Javascript Compression API

Downloads

263

Readme

Gzip and Gunzip Utility Functions

This module provides functions for compressing and decompressing data in browser using gzip compression. It leverages the browser's built-in CompressionStream and DecompressionStream for efficient gzip operations.

Installation

To use this module, you can import the necessary functions from the gzip-utils module:

import {
  gzipString,
  gzipFile,
  gzipBlob,
  gzipUint8Array,
  gzipStream,
  gunzipString,
  gunzipFile,
  gunzipBlob,
  gunzipUint8Array,
  gunzipStream,
} from 'gzip-utils';

Functions

gzipString

Compresses a string using gzip compression. Output formats are base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gzipString(text: string, output: 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw'): Promise<string | Uint8Array | File | Blob>;

gzipFile

Compresses a file using gzip compression. Output formats are base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gzipFile(file: File, output: 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw'): Promise<string | Uint8Array | File | Blob>;

gzipBlob

Compresses a Blob using gzip compression. Output formats are base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gzipBlob(blob: Blob, output: 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw'): Promise<string | Uint8Array | File | Blob>;

gzipUint8Array

Compresses a Uint8Array using gzip compression. Output formats are base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gzipUint8Array(uint8Array: Uint8Array, output: 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw'): Promise<string | Uint8Array | File | Blob>;

gzipStream

Compresses a ReadableStream using gzip compression. Output formats are base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gzipStream(stream: ReadableStream, output: 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw'): Promise<string | Uint8Array | File | Blob>;

gunzipString

Decompresses a string using gzip compression. Input formats are base64, base64url and hex. Output formats are utf8, base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gunzipString(text: string, input: 'base64' | 'base64url' | 'hex', output: 'utf8' | 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw');

gunzipFile

Decompresses a file using gzip compression. Output formats are utf8, base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gunzipFile(file: File, output: 'utf8' | 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw');

gunzipBlob

Decompresses a Blob using gzip compression. Output formats are utf8, base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gunzipBlob(blob: Blob, output: 'utf8' | 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw');

gunzipUint8Array

Decompresses a Uint8Array using gzip compression. Output formats are utf8, base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gunzipUint8Array(uint8Array: Uint8Array, output: 'utf8' | 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw');

gunzipStream

Decompresses a ReadableStream using gzip compression. Output formats are utf8, base64, base64url, hex, file, blob and raw. Default is 'raw' format which returns Uint8Array.

async function gunzipStream(stream: ReadableStream, output: 'utf8' | 'base64' | 'base64url' | 'hex' | 'file' | 'blob' | 'raw' = 'raw', outputMimeType: string = 'text/plain', outputFileExtension: string = 'txt');

Usage

Here's an example of how you can use the gzipString function:

const compressedData = await gzipString('Hello, World!', 'base64');
console.log(compressedData);
const decompressedData = await gunzipString(compressedData, 'base64', 'utf8');
console.log(decompressedData);

Feel free to explore other functions provided by this module for your compression and decompression needs.