1 #include <node_api.h>
2 #include "../../js-native-api/common.h"
3
finalizer(napi_env env,void * data,void * hint)4 static void finalizer(napi_env env, void *data, void *hint) {
5 NODE_API_CALL_RETURN_VOID(env,
6 napi_throw_error(env, NULL, "Error during Finalize"));
7 }
8
9 static char buffer_data[12];
10
createExternalBuffer(napi_env env,napi_callback_info info)11 static napi_value createExternalBuffer(napi_env env, napi_callback_info info) {
12 napi_value buffer;
13 NODE_API_CALL(env, napi_create_external_buffer(env, sizeof(buffer_data),
14 buffer_data, finalizer, NULL, &buffer));
15 return buffer;
16 }
17
Init(napi_env env,napi_value exports)18 static napi_value Init(napi_env env, napi_value exports) {
19 napi_property_descriptor descriptors[] = {
20 DECLARE_NODE_API_PROPERTY("createExternalBuffer", createExternalBuffer),
21 };
22 NODE_API_CALL(env, napi_define_properties(
23 env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
24 return exports;
25 }
26
27 NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
28