truncateSync method

void truncateSync([
  1. num? len
])

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

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

Truncate part of the file

// if "my_file.txt" contains the text "hello world":
const 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"
file.close();

Implementation

void truncateSync([_i2.num? len]) {
  _i3.callMethod(
    this,
    'truncateSync',
    [len ?? _i6.undefined],
  );
}