Add descriptions for demux and compose

This commit is contained in:
Jerry Kurian
2019-09-09 15:54:29 -04:00
parent d33d8dcad3
commit 7aeea4815a
5 changed files with 60 additions and 134 deletions

View File

@@ -4,23 +4,17 @@ import { pipeline, Duplex, DuplexOptions } from "stream";
* Return a Readable stream of readable streams concatenated together
* @param streams Readable streams to concatenate
*/
// First Readable --> Readable
// First Transform | Duplex, Last Writable --> Writable
//
export function compose(
streams: Array<
NodeJS.ReadableStream | NodeJS.ReadWriteStream | NodeJS.WritableStream
>,
options?: DuplexOptions,
): Compose {
// Maybe just return a new stream here
if (streams.length < 2) {
throw new Error("At least two streams are required to compose");
}
const composed = new Compose(streams, options);
return composed;
return new Compose(streams, options);
}
enum EventSubscription {
@@ -97,4 +91,21 @@ export class Compose extends Duplex {
}
return this;
}
public once(event: string, cb: any) {
switch (eventsTarget[event]) {
case EventSubscription.First:
this.first.once(event, cb);
break;
case EventSubscription.Last:
this.last.once(event, cb);
break;
case EventSubscription.All:
this.streams.forEach(s => s.once(event, cb));
break;
default:
super.once(event, cb);
}
return this;
}
}