2017-01-10 14:26:23 +02:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const fs = require('fs');
|
2017-07-17 15:33:46 -07:00
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
|
|
|
|
const filepath = fixtures.path('x.txt');
|
2017-01-10 14:26:23 +02:00
|
|
|
const fd = fs.openSync(filepath, 'r');
|
|
|
|
const expected = 'xyz\n';
|
|
|
|
|
2017-12-28 21:57:24 -06:00
|
|
|
|
2017-01-10 14:26:23 +02:00
|
|
|
// Error must be thrown with string
|
2017-11-26 20:51:01 -08:00
|
|
|
common.expectsError(
|
|
|
|
() => fs.read(fd, expected.length, 0, 'utf-8', common.mustNotCall()),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
2018-03-19 13:33:46 +01:00
|
|
|
message: 'The "buffer" argument must be one of type Buffer or Uint8Array.' +
|
|
|
|
' Received type number'
|
2017-11-26 20:51:01 -08:00
|
|
|
}
|
|
|
|
);
|
2017-01-10 14:26:23 +02:00
|
|
|
|
2017-12-28 21:57:24 -06:00
|
|
|
[true, null, undefined, () => {}, {}].forEach((value) => {
|
|
|
|
common.expectsError(() => {
|
|
|
|
fs.read(value,
|
|
|
|
Buffer.allocUnsafe(expected.length),
|
|
|
|
0,
|
|
|
|
expected.length,
|
|
|
|
0,
|
|
|
|
common.mustNotCall());
|
2018-03-19 13:33:46 +01:00
|
|
|
}, {
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'The "fd" argument must be of type integer'
|
|
|
|
});
|
2017-12-28 21:57:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
common.expectsError(() => {
|
|
|
|
fs.read(fd,
|
|
|
|
Buffer.allocUnsafe(expected.length),
|
|
|
|
-1,
|
|
|
|
expected.length,
|
|
|
|
0,
|
|
|
|
common.mustNotCall());
|
|
|
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
|
|
|
message: 'The value of "offset" is out of range.' });
|
|
|
|
|
|
|
|
common.expectsError(() => {
|
|
|
|
fs.read(fd,
|
|
|
|
Buffer.allocUnsafe(expected.length),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
common.mustNotCall());
|
|
|
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
|
|
|
message: 'The value of "length" is out of range.' });
|
|
|
|
|
|
|
|
|
2017-11-26 20:51:01 -08:00
|
|
|
common.expectsError(
|
|
|
|
() => fs.readSync(fd, expected.length, 0, 'utf-8'),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
2018-03-19 13:33:46 +01:00
|
|
|
message: 'The "buffer" argument must be one of type Buffer or Uint8Array.' +
|
|
|
|
' Received type number'
|
2017-11-26 20:51:01 -08:00
|
|
|
}
|
|
|
|
);
|
2017-12-28 21:57:24 -06:00
|
|
|
|
|
|
|
[true, null, undefined, () => {}, {}].forEach((value) => {
|
|
|
|
common.expectsError(() => {
|
|
|
|
fs.readSync(value,
|
|
|
|
Buffer.allocUnsafe(expected.length),
|
|
|
|
0,
|
|
|
|
expected.length,
|
|
|
|
0);
|
2018-03-19 13:33:46 +01:00
|
|
|
}, {
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'The "fd" argument must be of type integer'
|
|
|
|
});
|
2017-12-28 21:57:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
common.expectsError(() => {
|
|
|
|
fs.readSync(fd,
|
|
|
|
Buffer.allocUnsafe(expected.length),
|
|
|
|
-1,
|
|
|
|
expected.length,
|
|
|
|
0);
|
|
|
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
|
|
|
message: 'The value of "offset" is out of range.' });
|
|
|
|
|
|
|
|
common.expectsError(() => {
|
|
|
|
fs.readSync(fd,
|
|
|
|
Buffer.allocUnsafe(expected.length),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
0);
|
|
|
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
|
|
|
message: 'The value of "length" is out of range.' });
|