File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -3502,6 +3502,24 @@ Truncates the file. No arguments other than a possible exception are
3502
3502
given to the completion callback . A file descriptor can also be passed as the
3503
3503
first argument . In this case, ` fs.ftruncate()` is called.
3504
3504
3505
+ ` ` ` mjs
3506
+ import { truncate } from 'fs';
3507
+ // Assuming that 'path/file.txt' is a regular file.
3508
+ truncate('path/file.txt', (err) => {
3509
+ if (err) throw err;
3510
+ console.log('path/file.txt was truncated');
3511
+ });
3512
+ ` ` `
3513
+
3514
+ ` ` ` cjs
3515
+ const { truncate } = require('fs');
3516
+ // Assuming that 'path/file.txt' is a regular file.
3517
+ truncate('path/file.txt', (err) => {
3518
+ if (err) throw err;
3519
+ console.log('path/file.txt was truncated');
3520
+ });
3521
+ ` ` `
3522
+
3505
3523
Passing a file descriptor is deprecated and may result in an error being thrown
3506
3524
in the future.
3507
3525
You can’t perform that action at this time.
0 commit comments