Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Deno.truncate

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.writeFile(file, new TextEncoder().encode("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.

function truncate(name: string, len?: number): Promise<void>;
§
truncate(name: string, len?: number): Promise<void>
[src]

§Parameters

§
name: string
[src]
§
len?: number optional
[src]

§Return Type

§
Promise<void>
[src]