Add char* constructor for Buffer
This commit is contained in:
parent
bc695475b9
commit
0cf03ab800
@ -92,6 +92,18 @@ Buffer* Buffer::New(size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Buffer* Buffer::New(char* data, size_t len) {
|
||||||
|
HandleScope scope;
|
||||||
|
|
||||||
|
Local<Value> arg = Integer::NewFromUnsigned(len);
|
||||||
|
Local<Object> obj = constructor_template->GetFunction()->NewInstance(1, &arg);
|
||||||
|
|
||||||
|
Buffer *buffer = ObjectWrap::Unwrap<Buffer>(obj);
|
||||||
|
|
||||||
|
memcpy(buffer->data_, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char* Buffer::Data(Handle<Object> obj) {
|
char* Buffer::Data(Handle<Object> obj) {
|
||||||
if (obj->HasIndexedPropertiesInPixelData()) {
|
if (obj->HasIndexedPropertiesInPixelData()) {
|
||||||
return (char*)obj->GetIndexedPropertiesPixelData();
|
return (char*)obj->GetIndexedPropertiesPixelData();
|
||||||
|
@ -35,6 +35,7 @@ class Buffer : public ObjectWrap {
|
|||||||
|
|
||||||
static void Initialize(v8::Handle<v8::Object> target);
|
static void Initialize(v8::Handle<v8::Object> target);
|
||||||
static Buffer* New(size_t length); // public constructor
|
static Buffer* New(size_t length); // public constructor
|
||||||
|
static Buffer* New(char *data, size_t len); // public constructor
|
||||||
static bool HasInstance(v8::Handle<v8::Value> val);
|
static bool HasInstance(v8::Handle<v8::Value> val);
|
||||||
|
|
||||||
static char* Data(v8::Handle<v8::Object>);
|
static char* Data(v8::Handle<v8::Object>);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user