node/test/simple/test-fs-write-sync.js

22 lines
490 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08: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-06-11 05:59:06 +08:00
var foo = 'foo';
var fd = fs.openSync(fn, 'w');
2010-08-17 12:10:49 +08:00
2010-12-05 07:20:34 +08:00
var written = fs.writeSync(fd, '');
2010-08-17 12:10:49 +08:00
assert.strictEqual(0, written);
2010-06-11 05:59:06 +08:00
fs.writeSync(fd, foo);
var bar = 'bár';
written = fs.writeSync(fd, new Buffer(bar), 0, Buffer.byteLength(bar));
assert.ok(written > 3);
fs.closeSync(fd);
2010-06-11 05:59:06 +08:00
assert.equal(fs.readFileSync(fn), 'foobár');