1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const path = require('path'); 5const fs = require('fs'); 6 7const tmpdir = require('../common/tmpdir'); 8tmpdir.refresh(); 9 10// fs.write with length > INT32_MAX 11 12common.skipIf32Bits(); 13 14let buf; 15try { 16 buf = Buffer.allocUnsafe(0x7FFFFFFF + 1); 17} catch (e) { 18 // If the exception is not due to memory confinement then rethrow it. 19 if (e.message !== 'Array buffer allocation failed') throw (e); 20 common.skip('skipped due to memory requirements'); 21} 22 23const filename = path.join(tmpdir.path, 'write9.txt'); 24fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => { 25 assert.throws(() => { 26 fs.write(fd, 27 buf, 28 0, 29 0x7FFFFFFF + 1, 30 0, 31 common.mustNotCall()); 32 }, { 33 code: 'ERR_OUT_OF_RANGE', 34 name: 'RangeError', 35 message: 'The value of "length" is out of range. ' + 36 'It must be >= 0 && <= 2147483647. Received 2147483648' 37 }); 38 39 fs.closeSync(fd); 40})); 41