1'use strict'; 2 3const common = require('../common'); 4const fixtures = require('../common/fixtures'); 5const fs = require('fs'); 6const assert = require('assert'); 7const filepath = fixtures.path('x.txt'); 8const fd = fs.openSync(filepath, 'r'); 9 10const expected = Buffer.from('xyz\n'); 11const defaultBufferAsync = Buffer.alloc(16384); 12const bufferAsOption = Buffer.allocUnsafe(expected.length); 13 14// Test not passing in any options object 15fs.read(fd, common.mustCall((err, bytesRead, buffer) => { 16 assert.strictEqual(bytesRead, expected.length); 17 assert.deepStrictEqual(defaultBufferAsync.length, buffer.length); 18})); 19 20// Test passing in an empty options object 21fs.read(fd, { position: 0 }, common.mustCall((err, bytesRead, buffer) => { 22 assert.strictEqual(bytesRead, expected.length); 23 assert.deepStrictEqual(defaultBufferAsync.length, buffer.length); 24})); 25 26// Test passing in options 27fs.read(fd, { 28 buffer: bufferAsOption, 29 offset: 0, 30 length: bufferAsOption.length, 31 position: 0 32}, 33 common.mustCall((err, bytesRead, buffer) => { 34 assert.strictEqual(bytesRead, expected.length); 35 assert.deepStrictEqual(bufferAsOption.length, buffer.length); 36 })); 37