summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-truncate-GH-6233.js
blob: 023d08b15101d7b6fbeae23c337a7e863fa30986 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');

var filename = common.tmpDir + '/truncate-file.txt';

common.refreshTmpDir();

// Synchronous test.
(function() {
  fs.writeFileSync(filename, '0123456789');
  assert.equal(fs.readFileSync(filename).toString(), '0123456789');
  fs.truncateSync(filename, 5);
  assert.equal(fs.readFileSync(filename).toString(), '01234');
})();

// Asynchronous test.
(function() {
  fs.writeFileSync(filename, '0123456789');
  assert.equal(fs.readFileSync(filename).toString(), '0123456789');
  fs.truncate(filename, 5, common.mustCall(function(err) {
    if (err) throw err;
    assert.equal(fs.readFileSync(filename).toString(), '01234');
  }));
})();