nodejs / node-addon-examples

Node.js C++ addon examples from http://nodejs.org/docs/latest/api/addons.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please provide example of napi operate arraybuffer.

gzx-miller opened this issue · 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