mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
33 lines
733 B
JavaScript
33 lines
733 B
JavaScript
|
require('../common');
|
||
|
var path = require('path')
|
||
|
, Buffer = require('buffer').Buffer
|
||
|
, fs = require('fs')
|
||
|
, fn = path.join(fixturesDir, 'write.txt')
|
||
|
, expected = new Buffer('hello')
|
||
|
, openCalled = 0
|
||
|
, writeCalled = 0;
|
||
|
|
||
|
|
||
|
fs.open(fn, '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(fn);
|
||
|
assert.deepEqual(found, expected.toString());
|
||
|
fs.unlinkSync(fn);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
process.addListener("exit", function () {
|
||
|
assert.equal(openCalled, 1);
|
||
|
assert.equal(writeCalled, 1);
|
||
|
});
|
||
|
|