- From: Domenic Denicola <notifications@github.com>
- Date: Wed, 09 Mar 2016 17:24:08 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Message-ID: <whatwg/streams/pull/430/c194603771@github.com>
OK, I have an idea. Maybe we talked about it before. What if we add some kind of `defaultChunkSize` or `defaultReaderChunkSize` option, which would allow the elimination of the `if` branching we see in both examples. So instead of
```js
if (controller.byobRequest) {
const v = controller.byobRequest.view;
return fs.read(fd, v.buffer, v.byteOffset, v.byteLength, position).then(bytesRead => {
if (bytesRead === 0) {
return fs.close(fd).then(() => controller.close());
} else {
position += bytesRead;
controller.byobRequest.respond(bytesRead);
}
});
} else {
// The consumer is using the default reader.
const buffer = new ArrayBuffer(DEFAULT_CHUNK_SIZE);
return fs.read(fd, buffer, 0, DEFAULT_CHUNK_SIZE, position).then(bytesRead => {
if (bytesRead === 0) {
return fs.close(fd).then(() => controller.close());
} else {
position += bytesRead;
controller.enqueue(new Uint8Array(buffer, 0, bytesRead));
}
});
}
```
we have the `byobRequest` always present for streams with `byob: true` and `defaultReaderChunkSize: DEFAULT_CHUNK_SIZE`.
The name doesn't need to be super-short since this is an advanced option used by stream creators. It could even be something like `defaultReaderAutoAllocateChunkSize`.
WDYT?
---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/430#issuecomment-194603771
Received on Thursday, 10 March 2016 01:24:41 UTC