2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-01-13 21:42:45 +01:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const path = require('path');
|
|
|
|
const Buffer = require('buffer').Buffer;
|
|
|
|
const fs = require('fs');
|
|
|
|
const filename = path.join(common.tmpDir, 'write.txt');
|
2016-01-25 15:00:06 -08:00
|
|
|
const expected = Buffer.from('hello');
|
2010-05-19 14:17:50 -04:00
|
|
|
|
2015-06-09 11:40:55 -07:00
|
|
|
common.refreshTmpDir();
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
fs.open(filename, 'w', 0o644, common.mustCall(function(err, fd) {
|
2010-05-19 14:17:50 -04:00
|
|
|
if (err) throw err;
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
fs.write(fd,
|
|
|
|
expected,
|
|
|
|
0,
|
|
|
|
expected.length,
|
|
|
|
null,
|
|
|
|
common.mustCall(function(err, written) {
|
|
|
|
if (err) throw err;
|
2010-05-19 14:17:50 -04:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
assert.equal(expected.length, written);
|
|
|
|
fs.closeSync(fd);
|
2010-05-19 14:17:50 -04:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
var found = fs.readFileSync(filename, 'utf8');
|
|
|
|
assert.deepStrictEqual(expected.toString(), found);
|
|
|
|
fs.unlinkSync(filename);
|
|
|
|
}));
|
|
|
|
}));
|