Idiomatic representation of { buffer, bytesRead }

Jason Orendorff jason.orendorff at gmail.com
Wed Mar 4 22:10:33 UTC 2015


On Wed, Mar 4, 2015 at 3:06 PM, Domenic Denicola <d at domenic.me> wrote:
> I thought of that. However, I found it a bit strange that passing this function a view onto bytes [256, 512] of a 1024-byte buffer would detach the entire 1024-byte buffer. What do you think?

It's a good point. I figured most callers will have allocated the
buffer themselves, most will only have one view into it at a time, and
most will ask for the whole thing to be filled; and by "most" I really
mean somewhere over 99.9%. Skimming your gist seemed to sort of
confirm my hunch, but don't take my word for it -- that's all the
research I did. All I know is, I've known about Python's
[file.readinto()
method](https://docs.python.org/3.5/library/io.html#io.RawIOBase.readinto)
for at least 15 years and never yet had a need for it.

Would it make it seem less strange if you specified the argument as a
"dictionary" with these properties:

    {buffer:, byteOffset:, byteLength:, constructor:}

...and then casually mention that DataViews and TypedArrays both
happen to quack in just this way?

-j


More information about the es-discuss mailing list