File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -3412,6 +3412,24 @@ Truncates the file. No arguments other than a possible exception are
34123412given to the completion callback . A file descriptor can also be passed as the
34133413first argument . In this case, ` fs.ftruncate()` is called.
34143414
3415+ ` ` ` mjs
3416+ import { truncate } from 'fs';
3417+ // Assuming that 'path/file.txt' is a regular file.
3418+ truncate('path/file.txt', (err) => {
3419+ if (err) throw err;
3420+ console.log('path/file.txt was truncated');
3421+ });
3422+ ` ` `
3423+
3424+ ` ` ` cjs
3425+ const { truncate } = require('fs');
3426+ // Assuming that 'path/file.txt' is a regular file.
3427+ truncate('path/file.txt', (err) => {
3428+ if (err) throw err;
3429+ console.log('path/file.txt was truncated');
3430+ });
3431+ ` ` `
3432+
34153433Passing a file descriptor is deprecated and may result in an error being thrown
34163434in the future.
34173435
You can’t perform that action at this time.
0 commit comments