nodejs/node-addon-examples

Please provide example of napi operate arraybuffer.

gzx-miller opened this issue · 1 comments

Please provide example of napi operate arraybuffer.
I want show ffmpeg decoded image to electron canvas.
So, I tried create a ArrayBuffer in js, then pass as param in napi function.
then, I load ffmpeg to decode image one by one,
but there is no clear way to copy image memory to this ArrayBuffer in napi one by one.

If you are talking about JPEG image

Napi::Buffer<uint8_t> jpeg_buffer = Napi::Buffer<uint8_t>::New(env, jpeg_packet->data, jpeg_packet->size);

This jpeg_buffer can be passed to JS caller as a return value