Support encoding
This commit is contained in:
parent
dcc547d798
commit
d74c506044
@ -82,7 +82,8 @@ static size_t ByteLength (Handle<String> string, enum encoding enc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Handle<Object> Buffer::New(Handle<String> string) {
|
Handle<Object> Buffer::New(Handle<String> string,
|
||||||
|
Handle<Value> encoding) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
|
||||||
// get Buffer from global scope.
|
// get Buffer from global scope.
|
||||||
@ -91,8 +92,9 @@ Handle<Object> Buffer::New(Handle<String> string) {
|
|||||||
assert(bv->IsFunction());
|
assert(bv->IsFunction());
|
||||||
Local<Function> b = Local<Function>::Cast(bv);
|
Local<Function> b = Local<Function>::Cast(bv);
|
||||||
|
|
||||||
Local<Value> argv[1] = { Local<Value>::New(string) };
|
Local<Value> argv[2] = { Local<Value>::New(string),
|
||||||
Local<Object> instance = b->NewInstance(1, argv);
|
Local<Value>::New(encoding) };
|
||||||
|
Local<Object> instance = b->NewInstance(2, argv);
|
||||||
|
|
||||||
return scope.Close(instance);
|
return scope.Close(instance);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,9 @@ class Buffer : public ObjectWrap {
|
|||||||
typedef void (*free_callback)(char *data, void *hint);
|
typedef void (*free_callback)(char *data, void *hint);
|
||||||
|
|
||||||
// C++ API for constructing fast buffer
|
// C++ API for constructing fast buffer
|
||||||
static v8::Handle<v8::Object> New(v8::Handle<v8::String> string);
|
static v8::Handle<v8::Object> New(
|
||||||
|
v8::Handle<v8::String> string,
|
||||||
|
v8::Handle<v8::Value> encoding = v8::Handle<v8::Value>());
|
||||||
|
|
||||||
static void Initialize(v8::Handle<v8::Object> target);
|
static void Initialize(v8::Handle<v8::Object> target);
|
||||||
static Buffer* New(size_t length); // public constructor
|
static Buffer* New(size_t length); // public constructor
|
||||||
|
@ -31,6 +31,7 @@ static Persistent<String> prev_sym;
|
|||||||
static Persistent<String> ondrain_sym;
|
static Persistent<String> ondrain_sym;
|
||||||
static Persistent<String> onerror_sym;
|
static Persistent<String> onerror_sym;
|
||||||
static Persistent<String> data_sym;
|
static Persistent<String> data_sym;
|
||||||
|
static Persistent<String> encoding_sym;
|
||||||
static Persistent<String> offset_sym;
|
static Persistent<String> offset_sym;
|
||||||
static Persistent<String> fd_sym;
|
static Persistent<String> fd_sym;
|
||||||
static Persistent<String> is_unix_socket_sym;
|
static Persistent<String> is_unix_socket_sym;
|
||||||
@ -65,6 +66,7 @@ void IOWatcher::Initialize(Handle<Object> target) {
|
|||||||
fd_sym = NODE_PSYMBOL("fd");
|
fd_sym = NODE_PSYMBOL("fd");
|
||||||
is_unix_socket_sym = NODE_PSYMBOL("isUnixSocket");
|
is_unix_socket_sym = NODE_PSYMBOL("isUnixSocket");
|
||||||
data_sym = NODE_PSYMBOL("data");
|
data_sym = NODE_PSYMBOL("data");
|
||||||
|
encoding_sym = NODE_PSYMBOL("encoding");
|
||||||
|
|
||||||
|
|
||||||
ev_prepare_init(&dumper, IOWatcher::Dump);
|
ev_prepare_init(&dumper, IOWatcher::Dump);
|
||||||
@ -321,9 +323,9 @@ void IOWatcher::Dump(EV_P_ ev_prepare *w, int revents) {
|
|||||||
|
|
||||||
if (data_v->IsString()) {
|
if (data_v->IsString()) {
|
||||||
// TODO: insert v8::String::Pointers() hack here.
|
// TODO: insert v8::String::Pointers() hack here.
|
||||||
// TODO: handle different encodings.
|
|
||||||
Local<String> s = data_v->ToString();
|
Local<String> s = data_v->ToString();
|
||||||
buf_object = Local<Object>::New(Buffer::New(s));
|
Local<Value> e = bucket->Get(encoding_sym);
|
||||||
|
buf_object = Local<Object>::New(Buffer::New(s, e));
|
||||||
bucket->Set(data_sym, buf_object);
|
bucket->Set(data_sym, buf_object);
|
||||||
} else if (Buffer::HasInstance(data_v)) {
|
} else if (Buffer::HasInstance(data_v)) {
|
||||||
buf_object = data_v->ToObject();
|
buf_object = data_v->ToObject();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user