Skip to main content

truncate

function Deno.truncate
allow-write
Jump to headingtruncate(
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 Deno.truncate("my_file.txt");

Truncate part of the file

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

Requires allow-write permission.

Parameters Jump to heading

Jump to headingname: string
optional
Jump to headinglen: number

Return Type Jump to heading

Promise<void>
Back to top