UNPKG

send-stream

Version:

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

40 lines (39 loc) 1.76 kB
import { ServerResponse } from 'node:http'; import type { ServerHttp2Stream } from 'node:http2'; import { Http2ServerResponse } from 'node:http2'; import type { Readable } from 'node:stream'; import type { ResponseHeaders } from './utils'; import type { StorageInfo, SendOptions } from './types'; import type { StorageError } from './errors'; /** * Stream response * @template AttachedData - attached data type */ export declare class StreamResponse<AttachedData> { statusCode: number; headers: ResponseHeaders; stream: Readable; storageInfo?: StorageInfo<AttachedData> | undefined; error?: StorageError<unknown> | undefined; /** * Create stream response * @param statusCode - the status code matching the required resource * @param headers - the response headers to be sent for the required resource * @param stream - the response stream to be sent for the required resource * @param storageInfo - the storage information for the required resource (if existing) * @param error - the error if the resource can not be found or openned for any reason */ constructor(statusCode: number, headers: ResponseHeaders, stream: Readable, storageInfo?: StorageInfo<AttachedData> | undefined, error?: StorageError<unknown> | undefined); /** * Send response to http response * @param res - http response * @param opts - options * @param opts.ignorePrematureClose - ignore premature close errors * @throws error when response is already closed */ send(res: ServerResponse | Http2ServerResponse | ServerHttp2Stream, { ignorePrematureClose }?: SendOptions): Promise<void>; /** * Disposes of resources within the stream response object */ dispose(): void; }