xref: /third_party/node/test/parallel/test-fs-read-promises-optional-params.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
1'use strict';
2
3const common = require('../common');
4const fixtures = require('../common/fixtures');
5const fs = require('fs');
6const read = require('util').promisify(fs.read);
7const assert = require('assert');
8const filepath = fixtures.path('x.txt');
9const fd = fs.openSync(filepath, 'r');
10
11const expected = Buffer.from('xyz\n');
12const defaultBufferAsync = Buffer.alloc(16384);
13const bufferAsOption = Buffer.allocUnsafe(expected.byteLength);
14
15read(fd, common.mustNotMutateObjectDeep({}))
16  .then(function({ bytesRead, buffer }) {
17    assert.strictEqual(bytesRead, expected.byteLength);
18    assert.deepStrictEqual(defaultBufferAsync.byteLength, buffer.byteLength);
19  })
20  .then(common.mustCall());
21
22read(fd, bufferAsOption, common.mustNotMutateObjectDeep({ position: 0 }))
23  .then(function({ bytesRead, buffer }) {
24    assert.strictEqual(bytesRead, expected.byteLength);
25    assert.deepStrictEqual(bufferAsOption.byteLength, buffer.byteLength);
26  })
27  .then(common.mustCall());
28

Indexes created Thu Nov 07 10:32:03 CST 2024