mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 20:29:23 +01:00
050d974a25
PR-URL: https://github.com/nodejs/node/pull/43819 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
28 lines
976 B
JavaScript
28 lines
976 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
const fs = require('fs');
|
|
const read = require('util').promisify(fs.read);
|
|
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.byteLength);
|
|
|
|
read(fd, common.mustNotMutateObjectDeep({}))
|
|
.then(function({ bytesRead, buffer }) {
|
|
assert.strictEqual(bytesRead, expected.byteLength);
|
|
assert.deepStrictEqual(defaultBufferAsync.byteLength, buffer.byteLength);
|
|
})
|
|
.then(common.mustCall());
|
|
|
|
read(fd, bufferAsOption, common.mustNotMutateObjectDeep({ position: 0 }))
|
|
.then(function({ bytesRead, buffer }) {
|
|
assert.strictEqual(bytesRead, expected.byteLength);
|
|
assert.deepStrictEqual(bufferAsOption.byteLength, buffer.byteLength);
|
|
})
|
|
.then(common.mustCall());
|