• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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