• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const common = require('../common');
4const fixtures = require('../common/fixtures');
5const assert = require('assert');
6const fs = require('fs');
7const filepath = fixtures.path('x.txt');
8const fd = fs.openSync(filepath, 'r');
9const fsPromises = fs.promises;
10
11const buffer = new Uint8Array();
12
13assert.throws(
14  () => fs.readSync(fd, buffer, 0, 10, 0),
15  {
16    code: 'ERR_INVALID_ARG_VALUE',
17    message: 'The argument \'buffer\' is empty and cannot be written. ' +
18    'Received Uint8Array(0) []'
19  }
20);
21
22assert.throws(
23  () => fs.read(fd, buffer, 0, 1, 0, common.mustNotCall()),
24  {
25    code: 'ERR_INVALID_ARG_VALUE',
26    message: 'The argument \'buffer\' is empty and cannot be written. ' +
27    'Received Uint8Array(0) []'
28  }
29);
30
31(async () => {
32  const filehandle = await fsPromises.open(filepath, 'r');
33  assert.rejects(
34    () => filehandle.read(buffer, 0, 1, 0),
35    {
36      code: 'ERR_INVALID_ARG_VALUE',
37      message: 'The argument \'buffer\' is empty and cannot be written. ' +
38               'Received Uint8Array(0) []'
39    }
40  );
41})().then(common.mustCall());
42