Skip to main content

truncateSync

method Deno.FsFile.prototype.truncateSync
Jump to headingFsFile.prototype.truncateSync(len?: number): void

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

Truncate the entire file

using file = Deno.openSync("my_file.txt", { write: true });
file.truncateSync();

Truncate part of the file

// if "my_file.txt" contains the text "hello world":
using file = Deno.openSync("my_file.txt", { write: true });
file.truncateSync(7);
const buf = new Uint8Array(100);
file.readSync(buf);
const text = new TextDecoder().decode(buf); // "hello w"

Parameters Jump to heading

optional
Jump to headinglen: number

Return Type Jump to heading

void
Back to top