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

How can I access a Buffer's underlying Uint8Array or the ArrayBuffer, either using JavaScript or C++? #3296

Closed
metabench opened this issue Oct 9, 2015 · 5 comments
Labels
buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers.

Comments

@metabench
Copy link

I have noted that Buffer is now built on top of Uint8Array, and have decided to make more extensive use of Uint8Array throughout my code rather than using Buffers (also to standardise compatibility with C++).

What I would like to do is modify some existing code that makes use of buffers, and get low-level access to the Uint8Array that holds the data. Is that possible purely using JavaScript, without doing any resource intensive operations like copying the buffer to a new array? How could it be done using C++?

@mscdex mscdex added question Issues that look for answers. buffer Issues and PRs related to the buffer subsystem. labels Oct 9, 2015
@mscdex
Copy link
Contributor

mscdex commented Oct 9, 2015

/cc @trevnorris

@trevnorris
Copy link
Contributor

What I would like to do is modify some existing code that makes use of buffers, and get low-level access to the Uint8Array that holds the data.

Buffer is a Uint8Array, with a defined __proto__. e.g. in C++ doing args[0]->IsUint8Array() will return true. There something specific you're looking for?

@metabench
Copy link
Author

@trevnorris Thanks for clarifying. I am also seeing (in JavaScript) that

buf instanceof Uint8Array; // true

I'll be able to plan my code migration accordingly.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 9, 2015

@metabench Is this solved?

@metabench
Copy link
Author

@ChALkeR Yes it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

5 participants