method promises.FileHandle.truncate
Usage in Deno
```typescript import { type promises } from "node:node__fs.d.ts"; ```
FileHandle.truncate(len?: number): Promise<void>
Truncates the file.
If the file was larger than `len` bytes, only the first `len` bytes will be
retained in the file.
The following example retains only the first four bytes of the file:
```js
import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}
```
If the file previously was shorter than `len` bytes, it is extended, and the
extended part is filled with null bytes (`'\0'`):
If `len` is negative then `0` will be used.
Promise<void>
Fulfills with `undefined` upon success.