diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 04e17ec4b2..ae59b63f14 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -92,6 +92,18 @@ Buffer* Buffer::New(size_t size) { } +Buffer* Buffer::New(char* data, size_t len) { + HandleScope scope; + + Local arg = Integer::NewFromUnsigned(len); + Local obj = constructor_template->GetFunction()->NewInstance(1, &arg); + + Buffer *buffer = ObjectWrap::Unwrap(obj); + + memcpy(buffer->data_, data, len); +} + + char* Buffer::Data(Handle obj) { if (obj->HasIndexedPropertiesInPixelData()) { return (char*)obj->GetIndexedPropertiesPixelData(); diff --git a/src/node_buffer.h b/src/node_buffer.h index 18dda5201a..d191eb62e3 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -35,6 +35,7 @@ class Buffer : public ObjectWrap { static void Initialize(v8::Handle target); static Buffer* New(size_t length); // public constructor + static Buffer* New(char *data, size_t len); // public constructor static bool HasInstance(v8::Handle val); static char* Data(v8::Handle);