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

32 lines
868 B
JavaScript
Raw Normal View History

common = require("../common");
assert = common.assert
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(common.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;
console.log('open done');
2010-08-17 12:10:49 +08:00
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.equal(0, written);
2010-08-17 12:10:49 +08:00
});
2010-02-20 08:02:30 +08:00
fs.write(fd, expected, 0, "utf8", function (err, written) {
console.log('write done');
2010-02-20 08:02:30 +08:00
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');
console.log('expected: ' + expected.toJSON());
console.log('found: ' + found.toJSON());
2010-02-20 08:02:30 +08:00
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
});