| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c8cbec4 commit 0f07abc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ const { | |||
| 20 | 20 | ERR_INVALID_RETURN_VALUE, | |
| 21 | 21 | ERR_MISSING_ARGS, | |
| 22 | 22 | ERR_STREAM_DESTROYED, | |
| 23 | + ERR_STREAM_PREMATURE_CLOSE, | ||
| 23 | 24 | }, | |
| 24 | 25 | AbortError, | |
| 25 | 26 | } = require('internal/errors'); | |
@@ -344,13 +345,24 @@ function pipelineImpl(streams, callback, opts) { | |||
| 344 | 345 | } | |
| 345 | 346 | ||
| 346 | 347 | function pipe(src, dst, finish, { end }) { | |
| 348 | + let ended = false; | ||
| 349 | + dst.on('close', () => { | ||
| 350 | + if (!ended) { | ||
| 351 | + // Finish if the destination closes before the source has completed. | ||
| 352 | + finish(new ERR_STREAM_PREMATURE_CLOSE()); | ||
| 353 | + } | ||
| 354 | + }); | ||
| 355 | + | ||
| 347 | 356 | src.pipe(dst, { end }); | |
| 348 | 357 | ||
| 349 | 358 | if (end) { | |
| 350 | 359 | // Compat. Before node v10.12.0 stdio used to throw an error so | |
| 351 | 360 | // pipe() did/does not end() stdio destinations. | |
| 352 | 361 | // Now they allow it but "secretly" don't close the underlying fd. | |
| 353 | - src.once('end', () => dst.end()); | ||
| 362 | + src.once('end', () => { | ||
| 363 | + ended = true; | ||
| 364 | + dst.end(); | ||
| 365 | + }); | ||
| 354 | 366 | } else { | |
| 355 | 367 | finish(); | |
| 356 | 368 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const { pipeline, Duplex, PassThrough } = require('stream'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const remote = new PassThrough(); | ||
| 8 | + const local = new Duplex({ | ||
| 9 | + read() {}, | ||
| 10 | + write(chunk, enc, callback) { | ||
| 11 | + callback(); | ||
| 12 | + } | ||
| 13 | + }); | ||
| 14 | + | ||
| 15 | + pipeline(remote, local, remote, common.mustCall((err) => { | ||
| 16 | + assert.strictEqual(err.code, 'ERR_STREAM_PREMATURE_CLOSE'); | ||
| 17 | + })); | ||
| 18 | + | ||
| 19 | + setImmediate(() => { | ||
| 20 | + remote.end(); | ||
| 21 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments