Skip to content

Convert Uint8Array to Buffer #22

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

Closed
mafintosh opened this issue Apr 7, 2014 · 7 comments
Closed

Convert Uint8Array to Buffer #22

mafintosh opened this issue Apr 7, 2014 · 7 comments

Comments

@mafintosh
Copy link
Contributor

Should we expose the augment function somehow to allow for converting an Uint8Array to a Buffer without having to do a copy (which I believe new Buffer(uint8array) does now) ?

@feross
Copy link
Owner

feross commented Apr 7, 2014

Perhaps we should. But I don't want people to use augment in a way where their code no longer works on the server. Currently, the API is identical to node's. Exposing this function would be the first difference.

We also can't change new Buffer(uint8array) to not do a copy because that would change semantics. Maybe we can export it as _augment so it's clear that you're doing something dirty when you use it, but some people might want/need to do it anyway.

@feross
Copy link
Owner

feross commented Apr 7, 2014

Another idea I had was to publish a separate module just for efficient augmenting and always update the two modules in lockstep if anything changes.

@mafintosh
Copy link
Contributor Author

Uhh I like the second one! So basically we'll have to

  1. expose augment from Buffer in a semi private way (Buffer._augment)
  2. publish uint8array-to-buffer which uses 1 to turn an uint8array into a buffer (without copying)

@feross
Copy link
Owner

feross commented Apr 8, 2014

Published buffer 2.1.8 which exposes Buffer._augment.

Published typedarray-to-buffer. Enjoy!

@mafintosh
Copy link
Contributor Author

Nice and fast iteration (as always!). Thanks a lot.

@feross
Copy link
Owner

feross commented Apr 8, 2014

Also, the tests are still running on testling, so ignore the failing badge which Github has cached.

https://ci.testling.com/feross/typedarray-to-buffer

@kalmigs
Copy link

kalmigs commented May 4, 2024

Published buffer 2.1.8 which exposes Buffer._augment.

Published typedarray-to-buffer. Enjoy!

Thanks for this, so it was really this easy to convert to buffer

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