Browse Source

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>
v0.11.14-release
Trevor Norris 10 years ago
parent
commit
a054f8eb29
  1. 3
      lib/net.js
  2. 3
      src/pipe_wrap.cc
  3. 4
      src/stream_wrap.cc
  4. 2
      src/stream_wrap.h
  5. 3
      src/tcp_wrap.cc
  6. 3
      src/tty_wrap.cc

3
lib/net.js

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

3
src/pipe_wrap.cc

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

4
src/stream_wrap.cc

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

2
src/stream_wrap.h

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

3
src/tcp_wrap.cc

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

3
src/tty_wrap.cc

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

Loading…
Cancel
Save