0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fs-readSync-optional-params.js
Lucas Holmquist 88b4e86fd7
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>
2020-04-02 18:34:31 +02:00

28 lines
884 B
JavaScript

'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 });