mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
807 B
34 lines
807 B
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
15 years ago
|
var path = require('path'),
|
||
|
Buffer = require('buffer').Buffer,
|
||
|
fs = require('fs'),
|
||
14 years ago
|
filename = path.join(common.tmpDir, 'write.txt'),
|
||
15 years ago
|
expected = new Buffer('hello'),
|
||
|
openCalled = 0,
|
||
|
writeCalled = 0;
|
||
15 years ago
|
|
||
|
|
||
14 years ago
|
fs.open(filename, 'w', 0644, function(err, fd) {
|
||
15 years ago
|
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);
|
||
|
|
||
15 years ago
|
var found = fs.readFileSync(filename, 'utf8');
|
||
15 years ago
|
assert.deepEqual(expected.toString(), found);
|
||
|
fs.unlinkSync(filename);
|
||
15 years ago
|
});
|
||
|
});
|
||
|
|
||
13 years ago
|
process.on('exit', function() {
|
||
15 years ago
|
assert.equal(1, openCalled);
|
||
|
assert.equal(1, writeCalled);
|
||
15 years ago
|
});
|
||
|
|