Method Description:
Sync version of Truncate (), File content interception operations.
Grammar:
Copy Code code as follows:
Fs.truncatesync (path, Len)
Because this method belongs to the FS module, it is necessary to introduce FS module (VAR fs= require ("FS") before use.
Receive parameters:
Path file paths
Len truncate length, leaving only the characters in the length of the character, and the excess portion will be cleared.
Example:
Copy Code code as follows:
var fs = require (' FS ');
Fs.truncatesync (' 126.txt ', 3);
Source:
Copy Code code as follows:
Fs.truncatesync = function (path, len) {
if (Util.isnumber (path)) {
Legacy
return Fs.ftruncatesync (path, Len);
}
if (util.isundefined (len)) {
len = 0;
}
Allow error to being thrown, but still close FD.
var fd = fs.opensync (path, ' r+ ');
try {
var ret = Fs.ftruncatesync (FD, Len);
finally {
Fs.closesync (FD);
}
return ret;
};