| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 18be476 commit a653f23
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1950,8 +1950,7 @@ function ReadStream(path, options) { | |||
| 1950 | 1950 | this.flags = options.flags === undefined ? 'r' : options.flags; | |
| 1951 | 1951 | this.mode = options.mode === undefined ? 0o666 : options.mode; | |
| 1952 | 1952 | ||
| 1953 | - this.start = typeof this.fd !== 'number' && options.start === undefined ? | ||
| 1954 | - 0 : options.start; | ||
| 1953 | + this.start = options.start; | ||
| 1955 | 1954 | this.end = options.end; | |
| 1956 | 1955 | this.autoClose = options.autoClose === undefined ? true : options.autoClose; | |
| 1957 | 1956 | this.pos = undefined; | |
@@ -1974,6 +1973,12 @@ function ReadStream(path, options) { | |||
| 1974 | 1973 | this.pos = this.start; | |
| 1975 | 1974 | } | |
| 1976 | 1975 | ||
| 1976 | + // Backwards compatibility: Make sure `end` is a number regardless of `start`. | ||
| 1977 | + // TODO(addaleax): Make the above typecheck not depend on `start` instead. | ||
| 1978 | + // (That is a semver-major change). | ||
| 1979 | + if (typeof this.end !== 'number') | ||
| 1980 | + this.end = Infinity; | ||
| 1981 | + | ||
| 1977 | 1982 | if (typeof this.fd !== 'number') | |
| 1978 | 1983 | this.open(); | |
| 1979 | 1984 | ||
@@ -2028,6 +2033,8 @@ ReadStream.prototype._read = function(n) { | |||
| 2028 | 2033 | ||
| 2029 | 2034 | if (this.pos !== undefined) | |
| 2030 | 2035 | toRead = Math.min(this.end - this.pos + 1, toRead); | |
| 2036 | + else | ||
| 2037 | + toRead = Math.min(this.end - this.bytesRead + 1, toRead); | ||
| 2031 | 2038 | ||
| 2032 | 2039 | // already read everything we were supposed to read! | |
| 2033 | 2040 | // treat as EOF. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ | |||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | const common = require('../common'); | |
| 24 | 24 | ||
| 25 | + const child_process = require('child_process'); | ||
| 25 | 26 | const assert = require('assert'); | |
| 26 | 27 | const fs = require('fs'); | |
| 27 | 28 | const fixtures = require('../common/fixtures'); | |
@@ -171,6 +172,31 @@ assert.throws(function() { | |||
| 171 | 172 | })); | |
| 172 | 173 | } | |
| 173 | 174 | ||
| 175 | + if (!common.isWindows) { | ||
| 176 | + // Verify that end works when start is not specified, and we do not try to | ||
| 177 | + // use positioned reads. This makes sure that this keeps working for | ||
| 178 | + // non-seekable file descriptors. | ||
| 179 | + common.refreshTmpDir(); | ||
| 180 | + const filename = `${common.tmpDir}/foo.pipe`; | ||
| 181 | + const mkfifoResult = child_process.spawnSync('mkfifo', [filename]); | ||
| 182 | + if (!mkfifoResult.error) { | ||
| 183 | + child_process.exec(`echo "xyz foobar" > '${filename}'`); | ||
| 184 | + const stream = new fs.createReadStream(filename, { end: 1 }); | ||
| 185 | + stream.data = ''; | ||
| 186 | + | ||
| 187 | + stream.on('data', function(chunk) { | ||
| 188 | + stream.data += chunk; | ||
| 189 | + }); | ||
| 190 | + | ||
| 191 | + stream.on('end', common.mustCall(function() { | ||
| 192 | + assert.strictEqual('xy', stream.data); | ||
| 193 | + fs.unlinkSync(filename); | ||
| 194 | + })); | ||
| 195 | + } else { | ||
| 196 | + common.printSkipMessage('mkfifo not available'); | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + | ||
| 174 | 200 | { | |
| 175 | 201 | // pause and then resume immediately. | |
| 176 | 202 | const pauseRes = fs.createReadStream(rangeFile); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments