mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
88b4e86fd7
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>
28 lines
884 B
JavaScript
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 });
|