| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| 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 | |||
| 3412 | 3412 | given to the completion callback. A file descriptor can also be passed as the | |
| 3413 | 3413 | first argument. In this case, `fs.ftruncate()` is called. | |
| 3414 | 3414 | ||
| 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 | + | ||
| 3415 | 3433 | Passing a file descriptor is deprecated and may result in an error being thrown | |
| 3416 | 3434 | in the future. | |
| 3417 | 3435 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments