Compare commits

...

2 Commits

@ -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({

@ -1,6 +1,6 @@
{
"name": "@promistream/read-file",
"version": "0.1.0",
"version": "0.1.1",
"main": "index.js",
"keywords": [
"promistream"

Loading…
Cancel
Save