node::Buffer helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility.
Allocate a new
node::Buffer object with the specified size and optional data. Calls
Note that when creating a
Nan::NewBuffer() and an existing
char*, it is assumed that the ownership of the pointer is being transferred to the new
Buffer for management.
node::Buffer instance is garbage collected and a
FreeCallback has not been specified,
data will be disposed of via a call to
You must not free the memory space manually once you have created a
Buffer in this way.
Nan::MaybeLocal<v8::Object> Nan::NewBuffer(uint32_t size) Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char* data, uint32_t size) Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char *data, size_t length, Nan::FreeCallback callback, void *hint)
Nan::NewBuffer() except that an implicit memcpy will occur within Node. Calls
Management of the
char* is left to the user, you should manually free the memory space if necessary as the new
Buffer will have its own copy.
Nan::MaybeLocal<v8::Object> Nan::CopyBuffer(const char *data, uint32_t size)
A free callback that can be provided to
The supplied callback will be invoked when the
Buffer undergoes garbage collection.
typedef void (*FreeCallback)(char *data, void *hint);