UNPKG

1.08 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.pipelineClose = void 0;
4function pipelineClose(name, readableDownstream, sourceReadable, streamDone, logger) {
5 readableDownstream.push(null); // this closes the stream, so downstream Readable will receive `end` and won't write anything
6 if (!sourceReadable) {
7 logger.warn(`${name} sourceReadable is not provided, readable stream will not be stopped`);
8 }
9 else {
10 logger.log(`${name} is calling readable.unpipe() to pause the stream`);
11 sourceReadable.unpipe(); // it is expected to pause the stream
12 if (!streamDone) {
13 logger.log(`${name} streamDone is not provided, will do readable.destroy right away`);
14 sourceReadable.destroy();
15 }
16 else {
17 void streamDone.then(() => {
18 logger.log(`${name} streamDone, calling readable.destroy()`);
19 sourceReadable.destroy(); // this throws ERR_STREAM_PREMATURE_CLOSE
20 });
21 }
22 }
23}
24exports.pipelineClose = pipelineClose;