diff --git a/index.js b/index.js index b01dd68..5a7dfd2 100644 --- a/index.js +++ b/index.js @@ -34,13 +34,15 @@ function doRead(handle, length) { return buffer; } else if (result.bytesRead < length) { // TODO: For possible future performance optimization, consider reusing the remaining Buffer allocation for a next read, if possible. Need more data on how often this case occurs first, though, to justify the added complexity. - return buffer.slice(0, length); + return buffer.slice(0, result.bytesRead); } else { throw new Error(`Read more bytes (${result.bytesRead}) than the specified 'length' (${length}); this should never happen!`); } }); } +// FIXME: This should probably *only* allow reading mode flags + module.exports = function createReadFileStream(_path, _options) { let [ path, options ] = validateArguments(arguments, [ [ "path", required, isString ], @@ -54,6 +56,9 @@ module.exports = function createReadFileStream(_path, _options) { let handlePromise = fs.open(path, options.flag, options.mode); + // Silence unhandled rejection warnings until later + handlePromise.catch(() => {}); + // TODO: Metadata, including stream label and file size/type/path return pipe([ simpleSource({