Rename construct
This commit is contained in:
parent
58a95a91d0
commit
a42560edfc
@ -9,14 +9,14 @@ export interface DemuxOptions extends DuplexOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function demux(
|
export function demux(
|
||||||
construct: (
|
pipelineConstructor: (
|
||||||
destKey?: string,
|
destKey?: string,
|
||||||
chunk?: any,
|
chunk?: any,
|
||||||
) => DemuxStreams | Array<DemuxStreams>,
|
) => DemuxStreams | Array<DemuxStreams>,
|
||||||
demuxBy: string | ((chunk: any) => string),
|
demuxBy: string | ((chunk: any) => string),
|
||||||
options?: DemuxOptions,
|
options?: DemuxOptions,
|
||||||
): Duplex {
|
): Duplex {
|
||||||
return new Demux(construct, demuxBy, options);
|
return new Demux(pipelineConstructor, demuxBy, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Demux extends Duplex {
|
class Demux extends Duplex {
|
||||||
@ -24,11 +24,14 @@ class Demux extends Duplex {
|
|||||||
[key: string]: Array<DemuxStreams>;
|
[key: string]: Array<DemuxStreams>;
|
||||||
};
|
};
|
||||||
private demuxer: (chunk: any) => string;
|
private demuxer: (chunk: any) => string;
|
||||||
private construct: (destKey?: string, chunk?: any) => Array<DemuxStreams>;
|
private pipelineConstructor: (
|
||||||
|
destKey?: string,
|
||||||
|
chunk?: any,
|
||||||
|
) => Array<DemuxStreams>;
|
||||||
private remultiplex: boolean;
|
private remultiplex: boolean;
|
||||||
private transform: Transform;
|
private transform: Transform;
|
||||||
constructor(
|
constructor(
|
||||||
construct: (
|
pipelineConstructor: (
|
||||||
destKey?: string,
|
destKey?: string,
|
||||||
chunk?: any,
|
chunk?: any,
|
||||||
) => DemuxStreams | Array<DemuxStreams>,
|
) => DemuxStreams | Array<DemuxStreams>,
|
||||||
@ -38,8 +41,8 @@ class Demux extends Duplex {
|
|||||||
super(options);
|
super(options);
|
||||||
this.demuxer =
|
this.demuxer =
|
||||||
typeof demuxBy === "string" ? chunk => chunk[demuxBy] : demuxBy;
|
typeof demuxBy === "string" ? chunk => chunk[demuxBy] : demuxBy;
|
||||||
this.construct = (destKey: string, chunk?: any) => {
|
this.pipelineConstructor = (destKey: string, chunk?: any) => {
|
||||||
const pipeline = construct(destKey, chunk);
|
const pipeline = pipelineConstructor(destKey, chunk);
|
||||||
return Array.isArray(pipeline) ? pipeline : [pipeline];
|
return Array.isArray(pipeline) ? pipeline : [pipeline];
|
||||||
};
|
};
|
||||||
this.remultiplex =
|
this.remultiplex =
|
||||||
@ -62,7 +65,7 @@ class Demux extends Duplex {
|
|||||||
public async _write(chunk: any, encoding: any, cb: any) {
|
public async _write(chunk: any, encoding: any, cb: any) {
|
||||||
const destKey = this.demuxer(chunk);
|
const destKey = this.demuxer(chunk);
|
||||||
if (this.streamsByKey[destKey] === undefined) {
|
if (this.streamsByKey[destKey] === undefined) {
|
||||||
const newPipelines = this.construct(destKey, chunk);
|
const newPipelines = this.pipelineConstructor(destKey, chunk);
|
||||||
this.streamsByKey[destKey] = newPipelines;
|
this.streamsByKey[destKey] = newPipelines;
|
||||||
|
|
||||||
newPipelines.forEach(newPipeline => {
|
newPipelines.forEach(newPipeline => {
|
||||||
|
Loading…
Reference in New Issue
Block a user