node/test/parallel/test-stream-pipeline-duplex.js
Robert Nagy e4bf5dc581
stream: finish pipeline if dst closes before src
If the destination stream is closed before the source has completed
the pipeline should finnish with premature close.

Fixes: https://github.com/nodejs/node/issues/43682

PR-URL: https://github.com/nodejs/node/pull/43701
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2022-07-11 11:25:05 +01:00

22 lines
447 B
JavaScript

'use strict';
const common = require('../common');
const { pipeline, Duplex, PassThrough } = require('stream');
const assert = require('assert');
const remote = new PassThrough();
const local = new Duplex({
read() {},
write(chunk, enc, callback) {
callback();
}
});
pipeline(remote, local, remote, common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_PREMATURE_CLOSE');
}));
setImmediate(() => {
remote.end();
});