UNPKG

797 BPlain TextView Raw
1import { Writable } from 'stream'
2import { DeferredPromise } from '@naturalcycles/js-lib'
3import { TransformOptions } from '../stream.model'
4
5export interface WritableVoidOptions extends TransformOptions {
6 /**
7 * If set - it will be Resolved when the Stream is done (after final.cb)
8 */
9 streamDone?: DeferredPromise
10}
11
12/**
13 * Use as a "null-terminator" of stream.pipeline.
14 * It consumes the stream as quickly as possible without doing anything.
15 * Put it in the end of your pipeline in case it ends with Transform that needs a consumer.
16 */
17export function writableVoid(opt: WritableVoidOptions = {}): Writable {
18 return new Writable({
19 objectMode: true,
20 ...opt,
21 write(chunk, _, cb) {
22 cb()
23 },
24 final(cb) {
25 cb()
26 opt.streamDone?.resolve()
27 },
28 })
29}