fs: make parameters optional for readSync

This makes the offset, length and position parameters optional by
passing in an options object.

PR-URL: https://github.com/nodejs/node/pull/32460
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Lucas Holmquist authored and Anna Henningsen committed 2020-04-02 18:34:31 +02:00
1 parent 05da0bbadc
commit 88b4e86fd7
3 files changed
+65

No files matched your search

@@ -0,0 +1,27 @@
'use strict';
require('../common');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const assert = require('assert');
const filepath = fixtures.path('x.txt');
const fd = fs.openSync(filepath, 'r');
const expected = Buffer.from('xyz\n');
function runTest(defaultBuffer, options) {
const result = fs.readSync(fd, defaultBuffer, options);
assert.strictEqual(result, expected.length);
assert.deepStrictEqual(defaultBuffer, expected);
}
// Test passing in an empty options object
runTest(Buffer.allocUnsafe(expected.length), { position: 0 });
// Test not passing in any options object
runTest(Buffer.allocUnsafe(expected.length));
// Test passing in options
runTest(Buffer.allocUnsafe(expected.length), { offset: 0,
length: expected.length,
position: 0 });