1'use strict'; 2 3const common = require('../common'); 4 5const assert = require('assert'); 6const path = require('path'); 7const { writeFile, readFile } = require('fs').promises; 8const tmpdir = require('../common/tmpdir'); 9tmpdir.refresh(); 10 11const fn = path.join(tmpdir.path, 'large-file'); 12 13async function validateReadFile() { 14 // Creating large buffer with random content 15 const buffer = Buffer.from( 16 Array.apply(null, { length: 16834 * 2 }) 17 .map(Math.random) 18 .map((number) => (number * (1 << 8))) 19 ); 20 21 // Writing buffer to a file then try to read it 22 await writeFile(fn, buffer); 23 const readBuffer = await readFile(fn); 24 assert.strictEqual(readBuffer.equals(buffer), true); 25} 26 27async function validateReadFileProc() { 28 // Test to make sure reading a file under the /proc directory works. Adapted 29 // from test-fs-read-file-sync-hostname.js. 30 // Refs: 31 // - https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0 32 // - https://github.com/nodejs/node/issues/21331 33 34 // Test is Linux-specific. 35 if (!common.isLinux) 36 return; 37 38 const hostname = await readFile('/proc/sys/kernel/hostname'); 39 assert.ok(hostname.length > 0); 40} 41 42validateReadFile() 43 .then(() => validateReadFileProc()) 44 .then(common.mustCall()); 45