Skip to content
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

Merged
merged 1 commit into from
Dec 24, 2018
Merged

Conversation

styfle
Copy link
Contributor

@styfle styfle commented Dec 22, 2018

This is hard to document so I mostly linked to the Node docs which has pretty good descriptions of the divergences.

@littledan
Copy link
Owner

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.

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)
Copy link

@joyeecheung joyeecheung Dec 23, 2018

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).

@joyeecheung
Copy link

joyeecheung commented Dec 23, 2018

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)

@styfle
Copy link
Contributor Author

styfle commented Dec 23, 2018

@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 Buffer anymore now that I look at the code.

The other divergence (in my opinion) is the use of Blob in browsers but it doesn't appear to be in Node see this question.

I'm just going to close this ticket and let someone else who is more knowledgeable write it 🤷‍♂️

@styfle styfle closed this Dec 23, 2018
@littledan
Copy link
Owner

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.

@styfle styfle reopened this Dec 24, 2018
@littledan littledan merged commit ead8455 into littledan:master Dec 24, 2018
@littledan
Copy link
Owner

The mismatch of missing Blob would also be an interesting thing to write about!

@styfle styfle deleted the patch-1 branch December 24, 2018 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants