MCPcopy Index your code
hub / github.com/nodejs/node / truncateSync

Function truncateSync

lib/fs.js:1294–1312  ·  view source on GitHub ↗

* Synchronously truncates the file. * @param {string | Buffer | URL} path * @param {number} [len] * @returns {void}

(path, len)

Source from the content-addressed store, hash-verified

1292 * @returns {void}
1293 */
1294function truncateSync(path, len) {
1295 if (len === undefined) {
1296 len = 0;
1297 }
1298
1299 const h = vfsState.handlers;
1300 if (h !== null) {
1301 const result = h.truncateSync(path, len);
1302 if (result !== undefined) return;
1303 }
1304
1305 // Allow error to be thrown, but still close fd.
1306 const fd = fs.openSync(path, 'r+');
1307 try {
1308 fs.ftruncateSync(fd, len);
1309 } finally {
1310 fs.closeSync(fd);
1311 }
1312}
1313
1314/**
1315 * Truncates the file descriptor.

Callers

nothing calls this directly

Calls 4

ftruncateSyncMethod · 0.80
truncateSyncMethod · 0.45
openSyncMethod · 0.45
closeSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…