1'use strict'; 2require('../common'); 3const assert = require('assert'); 4const path = require('path'); 5const fs = require('fs'); 6const tmpdir = require('../common/tmpdir'); 7const tmp = tmpdir.path; 8 9tmpdir.refresh(); 10 11const filename = path.resolve(tmp, 'truncate-sync-file.txt'); 12 13fs.writeFileSync(filename, 'hello world', 'utf8'); 14 15const fd = fs.openSync(filename, 'r+'); 16 17fs.truncateSync(fd, 5); 18assert(fs.readFileSync(fd).equals(Buffer.from('hello'))); 19 20fs.closeSync(fd); 21fs.unlinkSync(filename); 22