Deno.ftruncateSync - Deno documentation
function Deno.ftruncateSync
rid: number,
len?: number,
): void

This will be removed in Deno 2.0. See the Deno 1.x to 2.x Migration Guide for migration instructions.

Synchronously truncates or extends the specified file stream, to reach the specified len.

If len is not specified then the entire file contents are truncated as if len was set to 0.

If the file previously was larger than this new length, the extra data is lost.

If the file previously was shorter, it is extended, and the extended part reads as null bytes ('\0').

Truncate the entire file

const file = Deno.openSync(
  { read: true, write: true, truncate: true, create: true }

Truncate part of the file

const file = Deno.openSync(
 { read: true, write: true, create: true }
file.writeSync(new TextEncoder().encode("Hello World"));
Deno.ftruncateSync(file.rid, 7);
Deno.seekSync(file.rid, 0, Deno.SeekMode.Start);
const data = new Uint8Array(32);
Deno.readSync(file.rid, data);
console.log(new TextDecoder().decode(data)); // Hello W


rid: number
len: number

Return Type