mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +00:00

- changed `var` to `const` where variables were not reassigned. - changed `assert.equal` to `assert.strictEqual` because there was no downside to being more rigorous. PR-URL: https://github.com/nodejs/node/pull/9978 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
22 lines
587 B
JavaScript
22 lines
587 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const tmp = common.tmpDir;
|
|
common.refreshTmpDir();
|
|
const filename = path.resolve(tmp, 'truncate-file.txt');
|
|
|
|
fs.writeFileSync(filename, 'hello world', 'utf8');
|
|
const fd = fs.openSync(filename, 'r+');
|
|
fs.truncate(fd, 5, common.mustCall(function(err) {
|
|
assert.ok(!err);
|
|
assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello');
|
|
}));
|
|
|
|
process.on('exit', function() {
|
|
fs.closeSync(fd);
|
|
fs.unlinkSync(filename);
|
|
console.log('ok');
|
|
});
|