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

Expose all prototype methods as statics methods that accepts Uint8Array values #1

Open
Gozala opened this issue Apr 7, 2019 · 5 comments

Comments

@Gozala
Copy link
Owner

Gozala commented Apr 7, 2019

As per conversation on twitter https://twitter.com/hugomrdias/status/1114678814754463746 I propose we update this library to expose all methods as static methods so that Uint8Array instances can be passed and to make it possible to make Uint8Array a canonical type for passing around bytes rather than node's Buffer.

If all works out we can attempt to uplift changes to the upstream.

/cc @lidel @hugomrdias @mikeal

@Gozala
Copy link
Owner Author

Gozala commented Apr 7, 2019

It is also worth considering significant API surface overlaps with DataView missing pieces are:

  • toString with all the encoding (which I think is primary thing missing in web APIs).
  • write again with all the encodings
  • transcode
  • swap16 / swap32 / swap64 Not sure how big of a deal is this in practice ((I never needed it).

So I think it's fare to say it's mostly about text encoding / decoding in various encodings there for it might make sense to create TextEncoder / TextDecoder style libs for those encodings.

Node Buffer also has different behavior for slice from type arrays (quote from node docs):

Buffer instances are also Uint8Array instances. However, there are subtle incompatibilities with TypedArray. For example, whileArrayBuffer#slice() creates a copy of the slice, the implementation of Buffer#slice() creates a view over the existing Buffer without copying, making Buffer#slice() far more efficient.

However type arrays offer subarray method that behaves similar to slice on buffers so I don't think there is a need to deal with that.

@lidel
Copy link

lidel commented Apr 8, 2019

@Gozala
Copy link
Owner Author

Gozala commented Jul 15, 2019

Looks like @mikeal is on it https://github.com/mikeal/bytesish

@mikeal
Copy link

mikeal commented Jul 15, 2019

bytesish is certainly related to this issue, as they are tackling a similar underlying problem, but i don’t think that byteish actually solves this particular issue.

@Gozala
Copy link
Owner Author

Gozala commented Jul 15, 2019

You're are right. It's just my primary goal had being to get rid of Buffer dependency and if we can accomplish that with smaller library like bytesish instead it's even better.

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

No branches or pull requests

3 participants