2010-07-16 02:47:25 +08:00
|
|
|
common = require("../common");
|
|
|
|
assert = common.assert
|
2010-03-09 02:02:19 +08:00
|
|
|
var path = require('path');
|
2010-06-11 05:59:06 +08:00
|
|
|
var Buffer = require('buffer').Buffer;
|
2010-03-09 02:02:19 +08:00
|
|
|
var fs = require('fs');
|
2010-07-16 02:47:25 +08:00
|
|
|
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;
|
2010-06-24 08:40:51 +08:00
|
|
|
console.log('open done');
|
2010-08-17 12:10:49 +08:00
|
|
|
fs.write(fd, '', 0, 'utf8', function(err, written) {
|
2010-08-25 11:46:37 +08:00
|
|
|
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) {
|
2010-06-24 08:40:51 +08:00
|
|
|
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');
|
2010-06-24 08:40:51 +08:00
|
|
|
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 () {
|
2009-11-29 01:26:59 +08:00
|
|
|
assert.equal(expected, found);
|
2009-09-17 14:28:31 +08:00
|
|
|
});
|
|
|
|
|