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

28 lines
710 B
JavaScript
Raw Normal View History

require("../common");
var path = require('path');
2010-06-11 05:59:06 +08:00
var Buffer = require('buffer').Buffer;
var fs = require('fs');
var fn = path.join(fixturesDir, "write.txt");
2010-06-11 05:59:06 +08:00
var expected = "ümlaut.";
2009-09-17 14:28:31 +08:00
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;
2010-06-11 05:59:06 +08:00
assert.equal(Buffer.byteLength(expected), written);
2010-02-20 08:02:30 +08:00
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
});