• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const path = require('path');
5const fs = require('fs');
6const tmpdir = require('../common/tmpdir');
7const tmp = tmpdir.path;
8tmpdir.refresh();
9const filename = path.resolve(tmp, 'truncate-file.txt');
10
11fs.writeFileSync(filename, 'hello world', 'utf8');
12const fd = fs.openSync(filename, 'r+');
13
14const msg = 'Using fs.truncate with a file descriptor is deprecated.' +
15' Please use fs.ftruncate with a file descriptor instead.';
16
17
18common.expectWarning('DeprecationWarning', msg, 'DEP0081');
19fs.truncate(fd, 5, common.mustCall((err) => {
20  assert.ok(!err);
21  assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello');
22}));
23
24process.on('exit', () => {
25  fs.closeSync(fd);
26  fs.unlinkSync(filename);
27  console.log('ok');
28});
29