11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This test makes sure that `readFile()` always reads from the current 41cb0ef41Sopenharmony_ci// position of the file, instead of reading from the beginning of the file. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst path = require('path'); 91cb0ef41Sopenharmony_ciconst { writeFileSync } = require('fs'); 101cb0ef41Sopenharmony_ciconst { open } = require('fs').promises; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 131cb0ef41Sopenharmony_citmpdir.refresh(); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst fn = path.join(tmpdir.path, 'test.txt'); 161cb0ef41Sopenharmony_ciwriteFileSync(fn, 'Hello World'); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciasync function readFileTest() { 191cb0ef41Sopenharmony_ci const handle = await open(fn, 'r'); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci /* Read only five bytes, so that the position moves to five. */ 221cb0ef41Sopenharmony_ci const buf = Buffer.alloc(5); 231cb0ef41Sopenharmony_ci const { bytesRead } = await handle.read(buf, 0, 5, null); 241cb0ef41Sopenharmony_ci assert.strictEqual(bytesRead, 5); 251cb0ef41Sopenharmony_ci assert.strictEqual(buf.toString(), 'Hello'); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci /* readFile() should read from position five, instead of zero. */ 281cb0ef41Sopenharmony_ci assert.strictEqual((await handle.readFile()).toString(), ' World'); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci await handle.close(); 311cb0ef41Sopenharmony_ci} 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cireadFileTest() 351cb0ef41Sopenharmony_ci .then(common.mustCall()); 36