2010-12-05 00:20:34 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var path = require('path');
|
|
|
|
var fs = require('fs');
|
|
|
|
var fn = path.join(common.tmpDir, 'write.txt');
|
2010-05-19 20:17:50 +02:00
|
|
|
|
2010-06-10 23:59:06 +02:00
|
|
|
|
2010-12-05 20:15:30 +01:00
|
|
|
var foo = 'foo';
|
2010-05-19 20:17:50 +02:00
|
|
|
var fd = fs.openSync(fn, 'w');
|
2010-08-17 06:10:49 +02:00
|
|
|
|
2010-12-05 00:20:34 +01:00
|
|
|
var written = fs.writeSync(fd, '');
|
2010-08-17 06:10:49 +02:00
|
|
|
assert.strictEqual(0, written);
|
|
|
|
|
2010-06-10 23:59:06 +02:00
|
|
|
fs.writeSync(fd, foo);
|
|
|
|
|
2010-12-05 20:15:30 +01:00
|
|
|
var bar = 'bár';
|
2010-07-17 04:05:28 +02:00
|
|
|
written = fs.writeSync(fd, new Buffer(bar), 0, Buffer.byteLength(bar));
|
|
|
|
assert.ok(written > 3);
|
2010-05-19 20:17:50 +02:00
|
|
|
fs.closeSync(fd);
|
|
|
|
|
2010-06-10 23:59:06 +02:00
|
|
|
assert.equal(fs.readFileSync(fn), 'foobár');
|