Files
jsowell-charger-web/jsowell-ui/node_modules/nan/doc/buffers.md
Lemon f5e6e29f00 Merge branch 'dev-zza' into dev
# Conflicts:
#	jsowell-ui/.env.development
#	jsowell-ui/.env.staging
#	jsowell-ui/bin/build-sit.bat
#	jsowell-ui/bin/build.bat
#	jsowell-ui/src/api/adapayMember/adapayMember.js
#	jsowell-ui/src/api/pile/merchant.js
#	jsowell-ui/src/router/index.js
#	jsowell-ui/src/views/financial/financeDetail.vue
#	jsowell-ui/src/views/financial/merchant.vue
#	jsowell-ui/src/views/homeIndex/homeIndex.vue
#	jsowell-ui/src/views/login.vue
#	jsowell-ui/src/views/pile/basic/detail.vue
#	jsowell-ui/src/views/pile/station/components/SiteInfo.vue
#	jsowell-ui/src/views/pile/station/detail.vue
#	jsowell-ui/src/views/pile/station/orderReport.vue
2025-06-03 14:26:37 +08:00

2.1 KiB

Buffers

NAN's node::Buffer helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility.

Nan::NewBuffer()

Allocate a new node::Buffer object with the specified size and optional data. Calls node::Buffer::New().

Note that when creating a Buffer using Nan::NewBuffer() and an existing char*, it is assumed that the ownership of the pointer is being transferred to the new Buffer for management. When a node::Buffer instance is garbage collected and a FreeCallback has not been specified, data will be disposed of via a call to free(). You must not free the memory space manually once you have created a Buffer in this way.

Signature:

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::CopyBuffer()

Similar to Nan::NewBuffer() except that an implicit memcpy will occur within Node. Calls node::Buffer::Copy().

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.

Signature:

Nan::MaybeLocal<v8::Object> Nan::CopyBuffer(const char *data, uint32_t size)

Nan::FreeCallback()

A free callback that can be provided to Nan::NewBuffer(). The supplied callback will be invoked when the Buffer undergoes garbage collection.

Signature:

typedef void (*FreeCallback)(char *data, void *hint);