Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Gzip and Gunzip text, File, Blob, Uint8Array or stream using native Javascript Compression API
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.
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';
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');
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.
FAQs
Gzip and Gunzip text, File, Blob, Uint8Array or stream using native Javascript Compression API
We found that gzip-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.