Description
@dherman brought this up originally, and then it came up in a conversation with @willchan and @slightlyoff.
The idea would be something like:
var ab = rs.read();
// OR
var bytesWritten = rs.readInto(ab, offset);
There's lots of bikeshedding that could be done here (overload instead of separate method? What does the prior art in other languages and libraries do? How to handle overflows? etc.). But the argument is quite sound in principle: it would allow you to allocate a single contiguous array buffer, then fill it with multiple reads from the stream.
The alternative now would be concatenating array buffers, which (a) probably involves a copy in all existing browsers; (b) even if it were optimized (in a similar manner to string concatenation), would cause memory fragmentation/cache locality problems compared to the single contiguous buffer.
This would be for binary (and string?) streams only. It may be a good use case for a BinaryReadableStream
subclass.