summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/node_buffer.cc22
-rw-r--r--src/node_buffer.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 63db6107e0..f8d1a30879 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -376,6 +376,27 @@ Handle<Value> Buffer::Base64Slice(const Arguments &args) {
}
+// buffer.fill(value, start, end);
+Handle<Value> Buffer::Fill(const Arguments &args) {
+ HandleScope scope;
+
+ if (!args[0]->IsInt32()) {
+ return ThrowException(Exception::Error(String::New(
+ "value is not a number")));
+ }
+ int value = (char)args[0]->Int32Value();
+
+ Buffer *parent = ObjectWrap::Unwrap<Buffer>(args.This());
+ SLICE_ARGS(args[1], args[2])
+
+ memset( (void*)(parent->data_ + start),
+ value,
+ end - start);
+
+ return Undefined();
+}
+
+
// var bytesCopied = buffer.copy(target, targetStart, sourceStart, sourceEnd);
Handle<Value> Buffer::Copy(const Arguments &args) {
HandleScope scope;
@@ -734,6 +755,7 @@ void Buffer::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "binaryWrite", Buffer::BinaryWrite);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "base64Write", Buffer::Base64Write);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "ucs2Write", Buffer::Ucs2Write);
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "fill", Buffer::Fill);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "copy", Buffer::Copy);
NODE_SET_METHOD(constructor_template->GetFunction(),
diff --git a/src/node_buffer.h b/src/node_buffer.h
index 91f93dc1d0..e6d47452e9 100644
--- a/src/node_buffer.h
+++ b/src/node_buffer.h
@@ -117,6 +117,7 @@ class Buffer : public ObjectWrap {
static v8::Handle<v8::Value> Ucs2Write(const v8::Arguments &args);
static v8::Handle<v8::Value> ByteLength(const v8::Arguments &args);
static v8::Handle<v8::Value> MakeFastBuffer(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Fill(const v8::Arguments &args);
static v8::Handle<v8::Value> Copy(const v8::Arguments &args);
Buffer(v8::Handle<v8::Object> wrapper, size_t length);