Convert Uint8Array to Buffer #22

Closed
mafintosh opened this Issue Apr 7, 2014 · 6 comments

Comments

2 participants
Contributor

mafintosh commented Apr 7, 2014

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

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.

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.

Contributor

mafintosh commented Apr 7, 2014

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

feross commented Apr 8, 2014

Published buffer 2.1.8 which exposes Buffer._augment.

Published typedarray-to-buffer. Enjoy!

Contributor

mafintosh commented Apr 8, 2014

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

@mafintosh mafintosh closed this Apr 8, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment