How to use the truncateSync function from fs

Find comprehensive JavaScript fs.truncateSync code examples handpicked from public code repositorys.

86
87
88
89
90
91
92
93
94
95
exports.stat = co.promisify(fs.stat);
exports.statSync = fs.statSync;
exports.symlink = co.promisify(fs.symlink);
exports.symlinkSync = fs.symlinkSync;
exports.truncate = co.promisify(fs.truncate);
exports.truncateSync = fs.truncateSync;
exports.unlink = co.promisify(fs.unlink);
exports.unlinkSync = fs.unlinkSync;
exports.unwatchFile = fs.unwatchFile;
exports.utimes = co.promisify(fs.utimes);
fork icon22
star icon45
watch icon26

135
136
137
138
139
140
141
142
143
144
145
146
// filled with zeroes.


{
  const file1 = path.resolve(tmp, 'truncate-file-1.txt');
  fs.writeFileSync(file1, 'Hi');
  fs.truncateSync(file1, 4);
  assert(fs.readFileSync(file1).equals(Buffer.from('Hi\u0000\u0000')));
}


{
fork icon0
star icon0
watch icon0

+ 5 other calls in file