Skip to content

Passing contents of std::vector to a QuickJS function #7

@juanBerger

Description

@juanBerger

I'm missing something basic I think.
I have a file read into a vector:

std::vector<uint8_t>fileBuffer((std::istreambuf_iterator<char>(file)), (std::istreambuf_iterator<char>()));

I want to load it into a js Uint8Array. The only way that works for me so far is one byte at a time:

for (int i = 0; i < fileBuffer.size(); ++i){
  uint8_t byte = fileBuffer[i];
  jsContext.invoke("putByte", byte);
}

This is pretty slow. I can pass a pointer, but not sure how to de reference that on the js side.
What's the best way to do this?
Many Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions