@dishuostec/llrt-types
Version:
Type definitions for LLRT, Low Latency Runtime
203 lines (189 loc) • 5.79 kB
TypeScript
/**
* The `zlib` module provides compression functionality implemented using
* Gzip, Deflate/Inflate, Brotli and Zstandard.
*
* To access it:
*
* ```js
* import * as zlib from 'zlib';
* ```
*
* It is possible to compress or decompress data in a single step:
*
* ```js
* mport * as zlib from 'zlib';
*
* const input = '.................................';
* zlib.deflate(input, (err, buffer) => {
* if (err) {
* console.error('An error occurred:', err);
* process.exitCode = 1;
* }
* console.log(buffer.toString('base64'));
* });
*
* const buffer = Buffer.from('CwWASGVsbG8gV29ybGQD', 'base64');
* zlib.brotliDecompress(buffer, (err, buffer) => {
* if (err) {
* console.error('An error occurred:', err);
* process.exitCode = 1;
* }
* console.log(buffer.toString());
* });
*
* ```
*/
declare module "zlib" {
import { Buffer } from "buffer";
interface ZlibOptions {
level?: number | undefined; // compression only
}
interface ZstdOptions {
level?: number | undefined; // compression only
}
type InputType = string | ArrayBuffer | QuickJS.ArrayBufferView;
type CompressCallback = (error: Error | null, result: Buffer) => void;
/**
* Compress a chunk of data with `Deflate`.
*/
export function deflate(buf: InputType, callback: CompressCallback): void;
export function deflate(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
/**
* Compress a chunk of data with `Deflate`.
*/
export function deflateSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
* Compress a chunk of data with `DeflateRaw`.
*/
export function deflateRaw(buf: InputType, callback: CompressCallback): void;
export function deflateRaw(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
/**
* Compress a chunk of data with `DeflateRaw`.
*/
export function deflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
* Compress a chunk of data with `Gzip`.
*/
export function gzip(buf: InputType, callback: CompressCallback): void;
export function gzip(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
/**
* Compress a chunk of data with `Gzip`.
*/
export function gzipSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
* Decompress a chunk of data with `Inflate`.
*/
export function inflate(buf: InputType, callback: CompressCallback): void;
export function inflate(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
/**
* Decompress a chunk of data with `Inflate`.
*/
export function inflateSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
* Decompress a chunk of data with `InflateRaw`.
*/
export function inflateRaw(buf: InputType, callback: CompressCallback): void;
export function inflateRaw(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
/**
* Decompress a chunk of data with `InflateRaw`.
*/
export function inflateRawSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
* Decompress a chunk of data with `Gunzip`.
*/
export function gunzip(buf: InputType, callback: CompressCallback): void;
export function gunzip(
buf: InputType,
options: ZlibOptions,
callback: CompressCallback
): void;
/**
* Decompress a chunk of data with `Gunzip`.
*/
export function gunzipSync(buf: InputType, options?: ZlibOptions): Buffer;
/**
* Compress a chunk of data with `BrotliCompress`.
*/
export function brotliCompress(buf: InputType, callback: CompressCallback): void;
/**
* Compress a chunk of data with `BrotliCompress`.
*/
export function brotliCompressSync(buf: InputType): Buffer;
/**
* Decompress a chunk of data with `BrotliDecompress`.
*/
export function brotliDecompress(buf: InputType, callback: CompressCallback): void;
/**
* Decompress a chunk of data with `BrotliDecompress`.
*/
export function brotliDecompressSync(buf: InputType): Buffer;
/**
* Compress a chunk of data with `ZstdCompress`.
*/
export function zstdCompress(buf: InputType, callback: CompressCallback): void;
export function zstdCompress(
buf: InputType,
options: ZstdOptions,
callback: CompressCallback
): void;
/**
* Compress a chunk of data with `ZstdCompress`.
*/
export function zstdCompressSync(buf: InputType, options?: ZstdOptions): Buffer;
/**
* Decompress a chunk of data with `ZstdDecompress`.
*/
export function zstdDecompress(buf: InputType, callback: CompressCallback): void;
export function zstdDecompress(
buf: InputType,
options: ZstdOptions,
callback: CompressCallback
): void;
/**
* Decompress a chunk of data with `ZstdDecompress`.
*/
export function zstdDecompressSync(buf: InputType, options?: ZstdOptions): Buffer;
const _default: {
deflate: typeof deflate;
deflateSync: typeof deflateSync;
deflateRaw: typeof deflateRaw;
deflateRawSync: typeof deflateRawSync;
gzip: typeof gzip;
gzipSync: typeof gzipSync;
inflate: typeof inflate;
inflateSync: typeof inflateSync;
inflateRaw: typeof inflateRaw;
inflateRawSync: typeof inflateRawSync;
gunzip: typeof gunzip;
gunzipSync: typeof gunzipSync;
brotliCompress: typeof brotliCompress;
brotliCompressSync: typeof brotliCompressSync;
brotliDecompress: typeof brotliDecompress;
brotliDecompressSync: typeof brotliDecompressSync;
zstdCompress: typeof zstdCompress;
zstdCompressSync: typeof zstdCompressSync;
zstdDecompress: typeof zstdDecompress;
zstdDecompressSync: typeof zstdDecompressSync;
};
export default _default;
}