Method description:
File content interception operation.
grammar:
The code copy is as follows:
fs.ftruncate(fd, len, [callback(err)])
Since this method belongs to the fs module, it is necessary to introduce the fs module before use (var fs= require("fs") )
Receive parameters:
path file path
len truncates the length, retaining only the characters within the length of the character, and the excess will be cleared.
callback callback, passing an exception parameter err
example:
The code copy is as follows:
var fs = require('fs');
fs.ftruncate('126.txt', 2, function(err){
if(err){
throw err;
}
console.log('File content truncated successfully');
})
Source code:
The code copy is as follows:
fs.ftruncate = function(fd, len, callback) {
if (util.isFunction(len)) {
callback = len;
len = 0;
} else if (util.isUndefined(len)) {
len = 0;
}
binding.ftruncate(fd, len, makeCallback(callback));
};