Convert Uint8Array to Buffer
mafintosh opened this issue · 7 comments
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) ?
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.
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.
Uhh I like the second one! So basically we'll have to
- expose
augmentfromBufferin a semi private way (Buffer._augment) - publish
uint8array-to-bufferwhich uses 1 to turn an uint8array into a buffer (without copying)
Published buffer 2.1.8 which exposes Buffer._augment.
Published typedarray-to-buffer. Enjoy!
Nice and fast iteration (as always!). Thanks a lot.
Also, the tests are still running on testling, so ignore the failing badge which Github has cached.
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