Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Convert Uint8Array to Buffer #22

Closed
mafintosh opened this Issue · 6 comments

2 participants

@mafintosh

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
Owner

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
Owner

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

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
Owner

Published buffer 2.1.8 which exposes Buffer._augment.

Published typedarray-to-buffer. Enjoy!

@mafintosh

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

@mafintosh mafintosh closed this
@feross
Owner

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
Something went wrong with that request. Please try again.