Skip to content

Commit a51c40e

Browse files
legobeatmcmire
andauthored
feat: Allow overriding Duplex stream constructor options (#59)
* feat: Allow overriding Duplex stream constructor options --------- Co-authored-by: Elliot Winkler <[email protected]>
1 parent ed94efc commit a51c40e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Duplex } from 'readable-stream';
1+
import { Duplex, DuplexOptions } from 'readable-stream';
22
import type { Runtime } from 'webextension-polyfill';
33

44
type Log = (data: unknown, out: boolean) => void;
@@ -11,9 +11,13 @@ export default class PortDuplexStream extends Duplex {
1111
/**
1212
* @param port - An instance of WebExtensions Runtime.Port. See:
1313
* {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/Port}
14+
* @param streamOptions - stream options passed on to Duplex stream constructor
1415
*/
15-
constructor(port: Runtime.Port) {
16-
super({ objectMode: true });
16+
constructor(port: Runtime.Port, streamOptions: DuplexOptions = {}) {
17+
super({
18+
objectMode: true,
19+
...streamOptions,
20+
});
1721
this._port = port;
1822
this._port.onMessage.addListener((msg: unknown) => this._onMessage(msg));
1923
this._port.onDisconnect.addListener(() => this._onDisconnect());

0 commit comments

Comments
 (0)