0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/test/simple/test-fs-write-buffer.js
2010-05-19 14:59:03 -07:00

33 lines
763 B
JavaScript

require('../common');
var path = require('path'),
Buffer = require('buffer').Buffer,
fs = require('fs'),
filename = path.join(fixturesDir, 'write.txt'),
expected = new Buffer('hello'),
openCalled = 0,
writeCalled = 0;
fs.open(filename, 'w', 0644, function (err, fd) {
openCalled++;
if (err) throw err;
fs.write(fd, expected, 0, expected.length, null, function(err, written) {
writeCalled++;
if (err) throw err;
assert.equal(expected.length, written);
fs.closeSync(fd);
var found = fs.readFileSync(filename);
assert.deepEqual(expected.toString(), found);
fs.unlinkSync(filename);
});
});
process.addListener("exit", function () {
assert.equal(1, openCalled);
assert.equal(1, writeCalled);
});