diff --git a/src/functions/demux.ts b/src/functions/demux.ts index 3da1cbe..ac1a62a 100644 --- a/src/functions/demux.ts +++ b/src/functions/demux.ts @@ -9,14 +9,14 @@ export interface DemuxOptions extends DuplexOptions { } export function demux( - construct: ( + pipelineConstructor: ( destKey?: string, chunk?: any, ) => DemuxStreams | Array, demuxBy: string | ((chunk: any) => string), options?: DemuxOptions, ): Duplex { - return new Demux(construct, demuxBy, options); + return new Demux(pipelineConstructor, demuxBy, options); } class Demux extends Duplex { @@ -24,11 +24,14 @@ class Demux extends Duplex { [key: string]: Array; }; private demuxer: (chunk: any) => string; - private construct: (destKey?: string, chunk?: any) => Array; + private pipelineConstructor: ( + destKey?: string, + chunk?: any, + ) => Array; private remultiplex: boolean; private transform: Transform; constructor( - construct: ( + pipelineConstructor: ( destKey?: string, chunk?: any, ) => DemuxStreams | Array, @@ -38,8 +41,8 @@ class Demux extends Duplex { super(options); this.demuxer = typeof demuxBy === "string" ? chunk => chunk[demuxBy] : demuxBy; - this.construct = (destKey: string, chunk?: any) => { - const pipeline = construct(destKey, chunk); + this.pipelineConstructor = (destKey: string, chunk?: any) => { + const pipeline = pipelineConstructor(destKey, chunk); return Array.isArray(pipeline) ? pipeline : [pipeline]; }; this.remultiplex = @@ -62,7 +65,7 @@ class Demux extends Duplex { public async _write(chunk: any, encoding: any, cb: any) { const destKey = this.demuxer(chunk); if (this.streamsByKey[destKey] === undefined) { - const newPipelines = this.construct(destKey, chunk); + const newPipelines = this.pipelineConstructor(destKey, chunk); this.streamsByKey[destKey] = newPipelines; newPipelines.forEach(newPipeline => {