UNPKG

@backtrace/node

Version:
32 lines (31 loc) 1.27 kB
import { Writable, WritableOptions } from 'stream'; export type ChunkSplitterFactory = () => (chunk: Buffer, encoding: BufferEncoding) => [Buffer, Buffer?]; /** * Implementation of splitter should return either one or two `Buffer`s. * * The first `Buffer` will be written to the current chunk. * If the second `Buffer` is returned, `chunkifier` will create a new chunk and write the * second buffer to the new chunk. */ export type ChunkSplitter = (chunk: Buffer, encoding: BufferEncoding) => [Buffer, Buffer?]; /** * Implementation of chunk sink should return each time a new writable stream. * * `n` determines which stream it is in sequence. */ export type ChunkSink<S extends Writable = Writable> = (n: number) => S; export interface ChunkifierOptions extends WritableOptions { /** * Chunk splitter factory. The factory will be called when creating a new chunk. */ readonly splitter: ChunkSplitterFactory; /** * Chunk sink. The sink will be called when creating a new chunk. */ readonly sink: ChunkSink; readonly allowEmptyChunks?: boolean; } /** * Splits incoming data into chunks, writing them to the sink. */ export declare function chunkifier({ sink: streamFactory, ...options }: ChunkifierOptions): Writable;