choc icon indicating copy to clipboard operation
choc copied to clipboard

Passing contents of std::vector to a QuickJS function

Open juanBerger opened this issue 1 year ago • 1 comments

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!

juanBerger avatar Mar 03 '23 23:03 juanBerger