UNPKG

send-stream

Version:

Streaming file serving library with Range and conditional-GET support from file system or any streaming sources.

46 lines (45 loc) 1.49 kB
import { Readable, PassThrough } from 'node:stream'; import type { Uint8ArrayOrStreamRange } from './utils'; /** * Single buffer stream */ export declare class BufferStream extends Readable { private buffer; /** * Create a single buffer stream * @param buffer - content buffer or undefined if stream need to be empty */ constructor(buffer?: Uint8Array); /** * Read implementation */ _read(): void; /** * Destroy implementation * @param error - error or null * @param callback - callback to be called after destroy */ _destroy(error: Error | null, callback: (err?: Error | null) => void): void; } /** * Multi stream */ export declare class MultiStream extends PassThrough { private readonly ranges; private readonly onNextStream; private readonly onDestroy; /** * Create a multi streams stream * @param ranges - array of Buffer or StreamRange * @param onNextStream - function creating the Readable when needed * @param onDestroy - function called on close to release resources */ constructor(ranges: Uint8ArrayOrStreamRange[], onNextStream: (range: Uint8ArrayOrStreamRange) => Readable, onDestroy: () => Promise<void>); /** * Destroy implementation * @param error - error or null * @param callback - callback to be called after destroy */ _destroy(error: Error | null, callback: (err?: Error | null) => void): void; private sendNextRange; }