node/test/parallel/test-fs-truncate-fd.js
Myles Borins c5a18e748d Revert "fs: validate args of truncate functions in js"
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>
2016-08-04 09:37:17 -07:00

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');
});