0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/mjsunit/test-buffered-file.js
Ryan Dahl 3d8b14e6f7 node.fs.* moved into "/posix.js"
use require("/posix.js") to access them.
2009-10-28 22:45:46 +01:00

39 lines
999 B
JavaScript

node.mixin(require("common.js"));
var testTxt = node.path.join(fixturesDir, "test.txt");
var libDir = node.path.join(testDir, "../../lib");
require.paths.unshift(libDir);
node.mixin(require("/file.js"));
var fileUnlinked = false;
var file = new File(testTxt, "w+");
file.write("hello\n");
file.write("world\n");
setTimeout(function () {
file.write("hello\n");
file.write("world\n");
file.close().addCallback(function () {
error("file closed...");
var out = posix.cat(testTxt).wait();
print("the file contains: ");
p(out);
assertEquals("hello\nworld\nhello\nworld\n", out);
var file2 = new File(testTxt, "r");
file2.read(5).addCallback(function (data) {
puts("read(5): " + JSON.stringify(data));
assertEquals("hello", data);
posix.unlink(testTxt).addCallback(function () {
fileUnlinked = true;
});
});
file2.close();
});
}, 10);
process.addListener("exit", function () {
assertTrue(fileUnlinked);
puts("done");
});