Skip to content

Commit

Permalink
test: fs.write() if 3rd argument is a callback, not offset; easier wa…
Browse files Browse the repository at this point in the history
…y to resolve conflicts from nodejs#16822 and nodejs#16827
  • Loading branch information
Patrick Heneise committed Nov 15, 2017
1 parent 157df5a commit 7e3635f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions test/parallel/test-fs-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,29 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC;
fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
assert.ifError(err);

const done = common.mustCall((err, written) => {
console.log('open done');
fs.write(fd, '', 0, 'utf8', (err, written) => {
assert.strictEqual(0, written);
});
fs.write(fd, expected, 0, 'utf8', common.mustCall((err, written) => {
console.log('write done');
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
const found = fs.readFileSync(fn2, 'utf8');
console.log('expected: "%s"', expected);
console.log('found: "%s"', found);
fs.unlinkSync(fn2);
assert.strictEqual(expected, found);
});
}));
}));

const written = common.mustCall(function(err, written) {
fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
assert.ifError(err);
const done = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(0, written);
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
});

fs.write(fd, '', 0, 'utf8', written);
fs.write(fd, expected, 0, 'utf8', done);
fs.write(fd, expected, done);
}));

0 comments on commit 7e3635f

Please sign in to comment.