方法说明:
文件内容截取操作。
语法:
fs.ftruncate(fd, len, [callback(err)])
由于该方法属于fs模块,使用前需要引入fs模块(var fs= require(“fs”) )
接收参数:
path 文件路径
len 截断长度,只保留该字符长度内的字符,超出部分将被清除。
callback 回调,传递一个异常参数err
例子:
var fs = require('fs');
fs.ftruncate('126.txt', 2, function(err){
if(err){
throw err;
}
console.log('文件内容截断成功');
})
源码:
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));
};
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn