stream_wrap: Add support to write binary strings

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 <trev.norris@gmail.com>
This commit is contained in:
Trevor Norris 2014-09-03 03:36:17 -07:00
parent 81a9739108
commit a054f8eb29
6 changed files with 18 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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