Ende.truncate

function ยท requires --allow-write

function Ende.truncate(name: string, len?: number): Promise<void>

Truncates (or extends) the specified file, to reach the specified len. If len is not specified then the entire file contents are truncated.

Truncate the entire file

await Ende.truncate("my_file.txt");

Truncate part of the file

const file = await Ende.makeTempFile();
await Ende.writeTextFile(file, "Hello World");
await Ende.truncate(file, 7);
const data = await Ende.readFile(file);
console.log(new TextDecoder().decode(data));  // "Hello W"

Requires allow-write permission.