-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Buffers to DIVERGENCES.md #13
Conversation
Thanks for raising this point; I thought of Buffer as sort of a success case for unification already, but maybe I'm mistaken. I don't quite understand the extent of the incompatibility here. These days, Node has ArrayBuffer, TypedArray and DataView, right? Do APIs still require Buffer and not accept those other types? Do you think you could explain this in the "mitigation" section? |
- **Purpose**: Interaction with octet streams | ||
- **Web API**: [ArrayBuffer API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) | ||
- **Node.js API** [Buffer API](https://nodejs.org/api/buffer.html) | ||
- **Mitigation strategies**: Newer versions of Node.js have [Buffer.from(arrayBuffer)](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length) method and the `Buffer` is an instance of a [TypedArray](https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarray) with a few caveats. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer
is specifically, Uint8Array
(otherwise this is inconsistent with octet streams
mentioned above, although I am not sure if it's accurate to say that Buffers are intended for streams). There is also ongoing effort to support DataView
in APIs that accept Buffer
.
## Buffers | ||
|
||
- **Purpose**: Interaction with octet streams | ||
- **Web API**: [ArrayBuffer API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe equivalent of Node.js Buffer
is Uint8Array
, or DataView
, or at least ArrayBufferView
? (It's like a union of Uint8Array
and DataView
at this point).
Related (tracking?) issue for API support: nodejs/node#1826 AFAIK the API support in Node.js is Buffer > Uint8Array > Other TypedArrays > ArrayBuffer > DataView (where they make sense) |
@littledan I think it's been awhile since I worked with these binary types and I confused myself. Back in 2016, I had to do a bunch of conversions seen here. Today, I guess I don't really need the Node The other divergence (in my opinion) is the use of I'm just going to close this ticket and let someone else who is more knowledgeable write it 🤷♂️ |
Oh, sorry, this wasn't the effect I intended--I was thinking of merging your patch as is and asking if someone could add the subtlety that Joyee described as a follow-on. If you could summarize the information in this thread, I think it would be very useful. |
The mismatch of missing Blob would also be an interesting thing to write about! |
This is hard to document so I mostly linked to the Node docs which has pretty good descriptions of the divergences.