mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 10:54:13 +00:00

This reverts commit c86c1eeab5
.
original commit message:
This patch
1. moves the basic validation of arguments to `truncate` family
of functions to the JavaScript layer from the C++ layer.
2. makes sure that the File Descriptors are validated strictly.
PR-URL: #2498
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/7950
Reviewed-By: Julien Gilli <jgilli@nodejs.org>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
22 lines
567 B
JavaScript
22 lines
567 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
var path = require('path');
|
|
var fs = require('fs');
|
|
var tmp = common.tmpDir;
|
|
common.refreshTmpDir();
|
|
var filename = path.resolve(tmp, 'truncate-file.txt');
|
|
|
|
fs.writeFileSync(filename, 'hello world', 'utf8');
|
|
var fd = fs.openSync(filename, 'r+');
|
|
fs.truncate(fd, 5, common.mustCall(function(err) {
|
|
assert.ok(!err);
|
|
assert.equal(fs.readFileSync(filename, 'utf8'), 'hello');
|
|
}));
|
|
|
|
process.on('exit', function() {
|
|
fs.closeSync(fd);
|
|
fs.unlinkSync(filename);
|
|
console.log('ok');
|
|
});
|