mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
742 B
26 lines
742 B
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
|
|
var filename = common.tmpDir + '/truncate-file.txt';
|
|
|
|
common.refreshTmpDir();
|
|
|
|
// Synchronous test.
|
|
{
|
|
fs.writeFileSync(filename, '0123456789');
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '0123456789');
|
|
fs.truncateSync(filename, 5);
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '01234');
|
|
}
|
|
|
|
// Asynchronous test.
|
|
{
|
|
fs.writeFileSync(filename, '0123456789');
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '0123456789');
|
|
fs.truncate(filename, 5, common.mustCall(function(err) {
|
|
assert.ifError(err);
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '01234');
|
|
}));
|
|
}
|
|
|