node::Buffer::New() has a version where it takes a char * along with the size. Node assumes ownership of the memory at the char * and frees it using free() when the buffer is garbage collected. It also provides a version of New() where a deleter may be specified in case free() is not the right thing to do upon GC.
To avoid excessive copying, addons should be able to set the deleter to a no-op. To that end we need a version of napi_buffer_new() that accepts a deleter. I propose
napi_status napi_buffer_new_with_deleter(napi_env e,
char* data,
size_t size,
void (*deleter)(void*),
napi_value* result);
node::Buffer::New()has a version where it takes achar *along with the size. Node assumes ownership of the memory at thechar *and frees it usingfree()when the buffer is garbage collected. It also provides a version ofNew()where a deleter may be specified in casefree()is not the right thing to do upon GC.To avoid excessive copying, addons should be able to set the deleter to a no-op. To that end we need a version of
napi_buffer_new()that accepts a deleter. I propose