Browse Source

Add char* constructor for Buffer

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
0cf03ab800
  1. 12
      src/node_buffer.cc
  2. 1
      src/node_buffer.h

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();

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>);

Loading…
Cancel
Save