mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
doc: add code example to fs.truncate method
PR-URL: https://github.com/nodejs/node/pull/39454 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
05d7460747
commit
898db5a570
1 file changed
+18
@@ -3412,6 +3412,24 @@ Truncates the file. No arguments other than a possible exception are
|
||||
given to the completion callback. A file descriptor can also be passed as the
|
||||
first argument. In this case, `fs.ftruncate()` is called.
|
||||
|
||||
```mjs
|
||||
import { truncate } from 'fs';
|
||||
// Assuming that 'path/file.txt' is a regular file.
|
||||
truncate('path/file.txt', (err) => {
|
||||
if (err) throw err;
|
||||
console.log('path/file.txt was truncated');
|
||||
});
|
||||
```
|
||||
|
||||
```cjs
|
||||
const { truncate } = require('fs');
|
||||
// Assuming that 'path/file.txt' is a regular file.
|
||||
truncate('path/file.txt', (err) => {
|
||||
if (err) throw err;
|
||||
console.log('path/file.txt was truncated');
|
||||
});
|
||||
```
|
||||
|
||||
Passing a file descriptor is deprecated and may result in an error being thrown
|
||||
in the future.
|
||||
|
||||
|
||||
Reference in new issue
Block a user