Permalink
Browse files

Add char* constructor for Buffer

  • Loading branch information...
1 parent bc69547 commit 0cf03ab8002795fed572bfaa31c51cced553bc2c @ry ry committed Oct 11, 2010
Showing with 13 additions and 0 deletions.
  1. +12 −0 src/node_buffer.cc
  2. +1 −0 src/node_buffer.h
View
12 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<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) {
if (obj->HasIndexedPropertiesInPixelData()) {
return (char*)obj->GetIndexedPropertiesPixelData();
View
1 src/node_buffer.h
@@ -35,6 +35,7 @@ class Buffer : public ObjectWrap {
static void Initialize(v8::Handle<v8::Object> target);
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 char* Data(v8::Handle<v8::Object>);

0 comments on commit 0cf03ab

Please sign in to comment.