11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst path = require('path'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 71cb0ef41Sopenharmony_ciconst tmp = tmpdir.path; 81cb0ef41Sopenharmony_citmpdir.refresh(); 91cb0ef41Sopenharmony_ciconst filename = path.resolve(tmp, 'truncate-file.txt'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifs.writeFileSync(filename, 'hello world', 'utf8'); 121cb0ef41Sopenharmony_ciconst fd = fs.openSync(filename, 'r+'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst msg = 'Using fs.truncate with a file descriptor is deprecated.' + 151cb0ef41Sopenharmony_ci' Please use fs.ftruncate with a file descriptor instead.'; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cicommon.expectWarning('DeprecationWarning', msg, 'DEP0081'); 191cb0ef41Sopenharmony_cifs.truncate(fd, 5, common.mustSucceed(() => { 201cb0ef41Sopenharmony_ci assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello'); 211cb0ef41Sopenharmony_ci})); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciprocess.once('beforeExit', () => { 241cb0ef41Sopenharmony_ci fs.closeSync(fd); 251cb0ef41Sopenharmony_ci fs.unlinkSync(filename); 261cb0ef41Sopenharmony_ci console.log('ok'); 271cb0ef41Sopenharmony_ci}); 28