Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gzip-utils

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gzip-utils

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

Keywords

FAQs

Package last updated on 24 Dec 2023

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