-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.cpp
More file actions
31 lines (25 loc) · 790 Bytes
/
Copy pathaddon.cpp
File metadata and controls
31 lines (25 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <nan.h>
#include <functional>
#include <iostream>
using namespace Nan;
using namespace v8;
using namespace std;
// copy memory starting from start
// until length
char* readBytes(const char* start, uint32_t size) {
char* data = new char[size];
memcpy(data, start, size);
return data;
};
// node addon
NAN_METHOD(ReadBytes) {
Nan:: HandleScope Scope;
char* start = (char*) node::Buffer::Data(info[0]->ToObject());
unsigned int size = info[1]->Uint32Value();
char * retval = readBytes(start, size);
info.GetReturnValue().Set(Nan::NewBuffer(retval, size).ToLocalChecked());
}
NAN_MODULE_INIT(Init) {
Nan::Set(target, New<String>("readBytes").ToLocalChecked(),GetFunction(New<FunctionTemplate>(ReadBytes)).ToLocalChecked());
}
NODE_MODULE(addon, Init)