Skip to content

Commit

Permalink
stream do not need to be unpiped
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashenry committed Apr 7, 2020
1 parent a9211ff commit 2ecd4d7
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ export class EmptyStream extends Readable {
* Multi stream
*/
export class MultiStream extends PassThrough {
private currentStream?: Readable;
constructor(
private readonly ranges: BufferOrStreamRange[],
private readonly onNextStream: (stream: BufferOrStreamRange) => Readable,
private readonly onNextStream: (range: BufferOrStreamRange) => Readable,
private readonly onDestroy: () => Promise<void>
) {
super({ allowHalfOpen: false });
Expand All @@ -50,10 +49,6 @@ export class MultiStream extends PassThrough {

// tslint:disable-next-line: function-name
_destroy(error: Error | null, callback: (error: Error | null) => void) {
if (this.currentStream) {
this.currentStream.unpipe(this);
this.currentStream = undefined;
}
this.onDestroy()
.then(() => {
super._destroy(error, callback);
Expand All @@ -64,14 +59,14 @@ export class MultiStream extends PassThrough {
}

private sendNextRange() {
const streamContext = this.ranges.shift();
if (!streamContext) {
const currentRange = this.ranges.shift();
if (!currentRange) {
this.end(() => {
this.destroy();
});
return;
}
const stream = this.currentStream = this.onNextStream(streamContext);
const stream = this.onNextStream(currentRange);

let onClose: () => void;
const onError = (error: Error) => {
Expand Down

0 comments on commit 2ecd4d7

Please sign in to comment.