From 4617409cd0e21e5ff83aed0b8d4c1f39bc078eac Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Wed, 15 May 2024 02:12:44 +0000 Subject: [PATCH 1/3] feat: Allow overriding substream options in createStream --- src/ObjectMultiplex.ts | 10 +++++++--- src/Substream.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ObjectMultiplex.ts b/src/ObjectMultiplex.ts index bacd619..b10be87 100644 --- a/src/ObjectMultiplex.ts +++ b/src/ObjectMultiplex.ts @@ -1,4 +1,4 @@ -import { Duplex, finished } from 'readable-stream'; +import { Duplex, finished, type DuplexOptions } from 'readable-stream'; import once from 'once'; import { Substream } from './Substream'; @@ -20,7 +20,7 @@ export class ObjectMultiplex extends Duplex { this._substreams = {}; } - createStream(name: string): Substream { + createStream(name: string, opts: DuplexOptions = {}): Substream { // guard stream against destroyed already if (this.destroyed) { throw new Error( @@ -47,7 +47,11 @@ export class ObjectMultiplex extends Duplex { } // create substream - const substream = new Substream({ parent: this, name }); + const substream = new Substream({ + name, + parent: this, + ...opts, + }); this._substreams[name] = substream; // listen for parent stream to end diff --git a/src/Substream.ts b/src/Substream.ts index c2c0c92..9ab214e 100644 --- a/src/Substream.ts +++ b/src/Substream.ts @@ -1,7 +1,7 @@ -import { Duplex } from 'readable-stream'; +import { Duplex, type DuplexOptions } from 'readable-stream'; import { ObjectMultiplex } from './ObjectMultiplex'; -export interface SubstreamOptions { +export interface SubstreamOptions extends DuplexOptions { parent: ObjectMultiplex; name: string; } @@ -11,8 +11,11 @@ export class Substream extends Duplex { private readonly _name: string; - constructor({ parent, name }: SubstreamOptions) { - super({ objectMode: true }); + constructor({ parent, name, ...streamOptions }: SubstreamOptions) { + super({ + objectMode: true, + ...streamOptions, + }); this._parent = parent; this._name = name; } From 3455cb57e201a71213451a1093406c8574512f89 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Wed, 15 May 2024 02:13:26 +0000 Subject: [PATCH 2/3] chore: Use specific type for constructor options --- src/ObjectMultiplex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ObjectMultiplex.ts b/src/ObjectMultiplex.ts index b10be87..e436767 100644 --- a/src/ObjectMultiplex.ts +++ b/src/ObjectMultiplex.ts @@ -12,7 +12,7 @@ interface Chunk { export class ObjectMultiplex extends Duplex { private _substreams: Record; - constructor(opts: Record = {}) { + constructor(opts: DuplexOptions = {}) { super({ ...opts, objectMode: true, From d6a08966a9cded42571f14c0c0a9bc0a70c80449 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Wed, 15 May 2024 02:13:57 +0000 Subject: [PATCH 3/3] fix: allow overriding any stream option --- src/ObjectMultiplex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ObjectMultiplex.ts b/src/ObjectMultiplex.ts index e436767..1d9f022 100644 --- a/src/ObjectMultiplex.ts +++ b/src/ObjectMultiplex.ts @@ -14,8 +14,8 @@ export class ObjectMultiplex extends Duplex { constructor(opts: DuplexOptions = {}) { super({ - ...opts, objectMode: true, + ...opts, }); this._substreams = {}; }