UNPKG

@versatiles/google-cloud

Version:
42 lines (41 loc) 2.01 kB
import type { IncomingHttpHeaders } from 'http'; import type { Transform } from 'stream'; import type { ResponseHeaders } from './response_headers.js'; export type EncodingType = 'br' | 'gzip' | 'raw'; /** * Interface representing tools for handling different encoding types. * Each property represents a functionality related to a specific encoding type. */ export interface EncodingTools { name: EncodingType; compressStream?: (fast: boolean, size?: number) => Transform; decompressStream?: () => Transform; compressBuffer?: (buffer: Buffer, fast: boolean) => Buffer | Promise<Buffer>; decompressBuffer?: (buffer: Buffer) => Buffer | Promise<Buffer>; setEncodingHeader: (headers: ResponseHeaders) => void; } /** * Record mapping encoding types to their respective tools. * Provides implementations for 'br', 'gzip', and 'raw' encodings. */ export declare const ENCODINGS: Record<EncodingType, EncodingTools>; /** * Parses the content encoding from the given HTTP headers and returns the corresponding encoding tools. * @param headers - The outgoing HTTP headers. * @returns The corresponding `EncodingTools` based on the content encoding header. * @throws Error if the content encoding is unknown. */ export declare function parseContentEncoding(contentEncoding?: string): EncodingTools; /** * Determines the best encoding supported by the client based on the `accept-encoding` HTTP header. * @param headers - The incoming HTTP headers. * @returns The best available `EncodingTools` based on client's preferences. */ export declare function findBestEncoding(headers: IncomingHttpHeaders): EncodingTools; /** * Checks if the given encoding is acceptable based on the `accept-encoding` HTTP header. * @param headers - The incoming HTTP headers. * @param encoding - The `EncodingTools` to check. * @returns `true` if the encoding is acceptable, otherwise `false`. */ export declare function acceptEncoding(headers: IncomingHttpHeaders, encoding: EncodingTools): boolean;