Skip to content

Commit

Permalink
stream_wrap: Add support to write binary strings
Browse files Browse the repository at this point in the history
node::StringBytes::Write() has appropriate support to write strings with
'binary' encoding. So expose that API through StreamWrap and allow
inheriting classes to use it.

Signed-off-by: Trevor Norris <[email protected]>
  • Loading branch information
trevnorris committed Sep 3, 2014
1 parent 81a9739 commit a054f8e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ Socket.prototype._write = function(data, encoding, cb) {

function createWriteReq(req, handle, data, encoding) {
switch (encoding) {
case 'binary':
return handle.writeBinaryString(req, data);

case 'buffer':
return handle.writeBuffer(req, data);

Expand Down
3 changes: 3 additions & 0 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ void PipeWrap::Initialize(Handle<Object> target,
StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t, "writeUtf8String", StreamWrap::WriteUtf8String);
NODE_SET_PROTOTYPE_METHOD(t, "writeUcs2String", StreamWrap::WriteUcs2String);
NODE_SET_PROTOTYPE_METHOD(t,
"writeBinaryString",
StreamWrap::WriteBinaryString);

NODE_SET_PROTOTYPE_METHOD(t, "bind", Bind);
NODE_SET_PROTOTYPE_METHOD(t, "listen", Listen);
Expand Down
4 changes: 4 additions & 0 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ void StreamWrap::WriteUcs2String(const FunctionCallbackInfo<Value>& args) {
WriteStringImpl<UCS2>(args);
}

void StreamWrap::WriteBinaryString(const FunctionCallbackInfo<Value>& args) {
WriteStringImpl<BINARY>(args);
}

void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());
Expand Down
2 changes: 2 additions & 0 deletions src/stream_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class StreamWrap : public HandleWrap {
static void WriteAsciiString(const v8::FunctionCallbackInfo<v8::Value>& args);
static void WriteUtf8String(const v8::FunctionCallbackInfo<v8::Value>& args);
static void WriteUcs2String(const v8::FunctionCallbackInfo<v8::Value>& args);
static void WriteBinaryString(
const v8::FunctionCallbackInfo<v8::Value>& args);

static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args);

Expand Down
3 changes: 3 additions & 0 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ void TCPWrap::Initialize(Handle<Object> target,
StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t, "writeUtf8String", StreamWrap::WriteUtf8String);
NODE_SET_PROTOTYPE_METHOD(t, "writeUcs2String", StreamWrap::WriteUcs2String);
NODE_SET_PROTOTYPE_METHOD(t,
"writeBinaryString",
StreamWrap::WriteBinaryString);
NODE_SET_PROTOTYPE_METHOD(t, "writev", StreamWrap::Writev);

NODE_SET_PROTOTYPE_METHOD(t, "open", Open);
Expand Down
3 changes: 3 additions & 0 deletions src/tty_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ void TTYWrap::Initialize(Handle<Object> target,
StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t, "writeUtf8String", StreamWrap::WriteUtf8String);
NODE_SET_PROTOTYPE_METHOD(t, "writeUcs2String", StreamWrap::WriteUcs2String);
NODE_SET_PROTOTYPE_METHOD(t,
"writeBinaryString",
StreamWrap::WriteBinaryString);

NODE_SET_PROTOTYPE_METHOD(t, "getWindowSize", TTYWrap::GetWindowSize);
NODE_SET_PROTOTYPE_METHOD(t, "setRawMode", SetRawMode);
Expand Down

0 comments on commit a054f8e

Please sign in to comment.