Giter Site home page Giter Site logo

gzip-utils's Introduction

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.

gzip-utils's People

Contributors

zoran-php avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.