node/test/simple/test-fs-write.js

27 lines
656 B
JavaScript
Raw Normal View History

require("../common");
var path = require('path');
var fs = require('fs');
var fn = path.join(fixturesDir, "write.txt");
2009-09-17 14:28:31 +08:00
var expected = "hello";
var found;
2010-02-20 08:02:30 +08:00
fs.open(fn, 'w', 0644, function (err, fd) {
if (err) throw err;
puts('open done');
fs.write(fd, expected, 0, "utf8", function (err, written) {
puts('write done');
if (err) throw err;
assert.equal(expected.length, written);
fs.closeSync(fd);
found = fs.readFileSync(fn, 'utf8');
puts('expected: ' + expected.toJSON());
puts('found: ' + found.toJSON());
fs.unlinkSync(fn);
2009-09-17 14:28:31 +08:00
});
});
process.addListener("exit", function () {
assert.equal(expected, found);
2009-09-17 14:28:31 +08:00
});