1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
common = require("../common");
assert = common.assert
var path = require('path'),
Buffer = require('buffer').Buffer,
fs = require('fs'),
filename = path.join(common.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, 'utf8');
assert.deepEqual(expected.toString(), found);
fs.unlinkSync(filename);
});
});
process.addListener("exit", function () {
assert.equal(1, openCalled);
assert.equal(1, writeCalled);
});
|