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 @@ -3452,6 +3452,24 @@ Truncates the file. No arguments other than a possible exception are
3452
3452
given to the completion callback . A file descriptor can also be passed as the
3453
3453
first argument . In this case, ` fs.ftruncate()` is called.
3454
3454
3455
+ ` ` ` mjs
3456
+ import { truncate } from 'fs';
3457
+ // Assuming that 'path/file.txt' is a regular file.
3458
+ truncate('path/file.txt', (err) => {
3459
+ if (err) throw err;
3460
+ console.log('path/file.txt was truncated');
3461
+ });
3462
+ ` ` `
3463
+
3464
+ ` ` ` cjs
3465
+ const { truncate } = require('fs');
3466
+ // Assuming that 'path/file.txt' is a regular file.
3467
+ truncate('path/file.txt', (err) => {
3468
+ if (err) throw err;
3469
+ console.log('path/file.txt was truncated');
3470
+ });
3471
+ ` ` `
3472
+
3455
3473
Passing a file descriptor is deprecated and may result in an error being thrown
3456
3474
in the future.
3457
3475
You can’t perform that action at this time.
0 commit comments