mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
fb254d2a83
PR-URL: https://github.com/nodejs/node/pull/32461 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = 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');
|
|
const defaultBufferAsync = Buffer.alloc(16384);
|
|
const bufferAsOption = Buffer.allocUnsafe(expected.length);
|
|
|
|
// Test passing in an empty options object
|
|
fs.read(fd, { position: 0 }, common.mustCall((err, bytesRead, buffer) => {
|
|
assert.strictEqual(bytesRead, expected.length);
|
|
assert.deepStrictEqual(defaultBufferAsync.length, buffer.length);
|
|
}));
|
|
|
|
// Test not passing in any options object
|
|
fs.read(fd, common.mustCall((err, bytesRead, buffer) => {
|
|
assert.strictEqual(bytesRead, expected.length);
|
|
assert.deepStrictEqual(defaultBufferAsync.length, buffer.length);
|
|
}));
|
|
|
|
// Test passing in options
|
|
fs.read(fd, {
|
|
buffer: bufferAsOption,
|
|
offset: 0,
|
|
length: bufferAsOption.length,
|
|
position: 0
|
|
},
|
|
common.mustCall((err, bytesRead, buffer) => {
|
|
assert.strictEqual(bytesRead, expected.length);
|
|
assert.deepStrictEqual(bufferAsOption.length, buffer.length);
|
|
}));
|