truncateAsync
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:
import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}
Content copied to clipboard
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.
Since
v10.0.0
Return
Fulfills with undefined
upon success.
Parameters
len=0