2018-06-11 19:14:52 +05:30
|
|
|
'use strict';
|
|
|
|
require('../common');
|
2018-09-28 14:50:04 +09:00
|
|
|
const common = require('../common');
|
2018-06-11 19:14:52 +05:30
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
|
|
|
const filepath = fixtures.path('x.txt');
|
|
|
|
const fd = fs.openSync(filepath, 'r');
|
2018-10-01 02:03:47 +09:00
|
|
|
const fsPromises = fs.promises;
|
2018-06-11 19:14:52 +05:30
|
|
|
|
|
|
|
const buffer = new Uint8Array();
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => fs.readSync(fd, buffer, 0, 10, 0),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
|
|
message: 'The argument \'buffer\' is empty and cannot be written. ' +
|
2019-12-19 16:12:30 +01:00
|
|
|
'Received Uint8Array(0) []'
|
2018-06-11 19:14:52 +05:30
|
|
|
}
|
|
|
|
);
|
2018-09-28 14:50:04 +09:00
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => fs.read(fd, buffer, 0, 1, 0, common.mustNotCall()),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
|
|
message: 'The argument \'buffer\' is empty and cannot be written. ' +
|
2019-12-19 16:12:30 +01:00
|
|
|
'Received Uint8Array(0) []'
|
2018-09-28 14:50:04 +09:00
|
|
|
}
|
|
|
|
);
|
2018-10-01 02:03:47 +09:00
|
|
|
|
|
|
|
(async () => {
|
2025-06-05 09:52:48 +08:00
|
|
|
await using filehandle = await fsPromises.open(filepath, 'r');
|
2018-10-01 02:03:47 +09:00
|
|
|
assert.rejects(
|
|
|
|
() => filehandle.read(buffer, 0, 1, 0),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
|
|
message: 'The argument \'buffer\' is empty and cannot be written. ' +
|
2019-12-19 16:12:30 +01:00
|
|
|
'Received Uint8Array(0) []'
|
2018-10-01 02:03:47 +09:00
|
|
|
}
|
2023-10-23 19:55:50 +02:00
|
|
|
).then(common.mustCall());
|
2020-07-14 17:45:39 +02:00
|
|
|
})().then(common.mustCall());
|