Fix utf8 scripts, add test. Thanks Urban.
This commit is contained in:
parent
e8a5d3d311
commit
b1588e78d9
12
src/file.cc
12
src/file.cc
@ -248,17 +248,19 @@ AfterUtf8Read (eio_req *req)
|
|||||||
|
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
|
||||||
Local<Value> argv[1];
|
Local<Value> argv[2];
|
||||||
|
|
||||||
if (req->result == 0) {
|
if (req->result == 0) {
|
||||||
// eof
|
// eof
|
||||||
argv[0] = Local<Value>::New(Null());
|
argv[0] = Local<Value>::New(Null());
|
||||||
|
argv[1] = Integer::New(0);
|
||||||
} else {
|
} else {
|
||||||
char *buf = reinterpret_cast<char*>(req->ptr2);
|
char *buf = reinterpret_cast<char*>(req->ptr2);
|
||||||
argv[0] = String::New(buf, req->result);
|
argv[0] = String::New(buf, req->result);
|
||||||
|
argv[1] = Integer::New(req->result);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise->EmitSuccess(1, argv);
|
promise->EmitSuccess(2, argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,10 +275,11 @@ AfterRawRead(eio_req *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
Local<Value> argv[1];
|
Local<Value> argv[2];
|
||||||
|
|
||||||
if (req->result == 0) {
|
if (req->result == 0) {
|
||||||
argv[0] = Local<Value>::New(Null());
|
argv[0] = Local<Value>::New(Null());
|
||||||
|
argv[1] = Integer::New(0);
|
||||||
} else {
|
} else {
|
||||||
char *buf = reinterpret_cast<char*>(req->ptr2);
|
char *buf = reinterpret_cast<char*>(req->ptr2);
|
||||||
size_t len = req->result;
|
size_t len = req->result;
|
||||||
@ -285,9 +288,10 @@ AfterRawRead(eio_req *req)
|
|||||||
array->Set(Integer::New(i), Integer::New(buf[i]));
|
array->Set(Integer::New(i), Integer::New(buf[i]));
|
||||||
}
|
}
|
||||||
argv[0] = array;
|
argv[0] = array;
|
||||||
|
argv[1] = Integer::New(req->result);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise->EmitSuccess(1, argv);
|
promise->EmitSuccess(2, argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,14 @@ node.fs.cat = function (path, encoding) {
|
|||||||
|
|
||||||
read_promise.addErrback(function () { cat_promise.emitError(); });
|
read_promise.addErrback(function () { cat_promise.emitError(); });
|
||||||
|
|
||||||
read_promise.addCallback(function (chunk) {
|
read_promise.addCallback(function (chunk, bytes_read) {
|
||||||
if (chunk) {
|
if (chunk) {
|
||||||
if (chunk.constructor == String)
|
if (chunk.constructor == String)
|
||||||
content += chunk;
|
content += chunk;
|
||||||
else
|
else
|
||||||
content = content.concat(chunk);
|
content = content.concat(chunk);
|
||||||
|
|
||||||
pos += chunk.length;
|
pos += bytes_read;
|
||||||
readChunk();
|
readChunk();
|
||||||
} else {
|
} else {
|
||||||
cat_promise.emitSuccess([content]);
|
cat_promise.emitSuccess([content]);
|
||||||
|
10
test/mjsunit/test-utf8-scripts.js
Normal file
10
test/mjsunit/test-utf8-scripts.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
include("mjsunit.js");
|
||||||
|
|
||||||
|
// üäö
|
||||||
|
|
||||||
|
puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη");
|
||||||
|
|
||||||
|
function onLoad () {
|
||||||
|
assertTrue( /Hellö Wörld/.test("Hellö Wörld") );
|
||||||
|
}
|
||||||
|
|
@ -479,7 +479,7 @@ reading from in the file.
|
|||||||
+encoding+ is either +node.UTF8+
|
+encoding+ is either +node.UTF8+
|
||||||
or +node.RAW+.
|
or +node.RAW+.
|
||||||
+
|
+
|
||||||
- on success: returns +data+, what was read from the file.
|
- on success: returns +data, bytes_read+, what was read from the file.
|
||||||
- on error: no parameters.
|
- on error: no parameters.
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user