summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-read-stream.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-03-13 20:42:33 +0100
committerAnna Henningsen <anna@addaleax.net>2018-03-17 12:36:29 +0100
commit2e376184f27df759ecf84f2361c7921635aed00d (patch)
tree3f088314cfa545381cdca5b5ec623aa5214d7196 /test/parallel/test-fs-read-stream.js
parent893432ad928e25854950c0b5c581dfb3081ed4bb (diff)
downloadandroid-node-v8-2e376184f27df759ecf84f2361c7921635aed00d.tar.gz
android-node-v8-2e376184f27df759ecf84f2361c7921635aed00d.tar.bz2
android-node-v8-2e376184f27df759ecf84f2361c7921635aed00d.zip
fs: fix `createReadStream(…, {end: n})` for non-seekable fds
82bdf8fba2d3f fixed an issue by silently modifying the `start` option for the case when only `end` is passed, in order to perform reads from a specified range in the file. However, that approach does not work for non-seekable files, since a numeric `start` option means that positioned reads will be used to read data from the file. This patch fixes that, and instead ends reading after a specified size by adjusting the read buffer size. This way we avoid re-introducing the bug that 82bdf8fba2d3f fixed, and align behaviour with the native file stream mechanism introduced in https://github.com/nodejs/node/pull/18936 as well. PR-URL: https://github.com/nodejs/node/pull/19329 Fixes: https://github.com/nodejs/node/issues/19240 Refs: https://github.com/nodejs/node/pull/18121 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chen Gang <gangc.cxy@foxmail.com>
Diffstat (limited to 'test/parallel/test-fs-read-stream.js')
-rw-r--r--test/parallel/test-fs-read-stream.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/parallel/test-fs-read-stream.js b/test/parallel/test-fs-read-stream.js
index 7fc7a0d56b..8b92eb1c7a 100644
--- a/test/parallel/test-fs-read-stream.js
+++ b/test/parallel/test-fs-read-stream.js
@@ -21,7 +21,9 @@
'use strict';
const common = require('../common');
+const tmpdir = require('../common/tmpdir');
+const child_process = require('child_process');
const assert = require('assert');
const fs = require('fs');
const fixtures = require('../common/fixtures');
@@ -178,6 +180,31 @@ common.expectsError(
}));
}
+if (!common.isWindows) {
+ // Verify that end works when start is not specified, and we do not try to
+ // use positioned reads. This makes sure that this keeps working for
+ // non-seekable file descriptors.
+ tmpdir.refresh();
+ const filename = `${tmpdir.path}/foo.pipe`;
+ const mkfifoResult = child_process.spawnSync('mkfifo', [filename]);
+ if (!mkfifoResult.error) {
+ child_process.exec(`echo "xyz foobar" > '${filename}'`);
+ const stream = new fs.createReadStream(filename, { end: 1 });
+ stream.data = '';
+
+ stream.on('data', function(chunk) {
+ stream.data += chunk;
+ });
+
+ stream.on('end', common.mustCall(function() {
+ assert.strictEqual('xy', stream.data);
+ fs.unlinkSync(filename);
+ }));
+ } else {
+ common.printSkipMessage('mkfifo not available');
+ }
+}
+
{
// pause and then resume immediately.
const pauseRes = fs.createReadStream(rangeFile);