truncateSync method

void truncateSync(
  1. String name, [
  2. num? len
])

Synchronously 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

Deno.truncateSync("my_file.txt");

Truncate part of the file

const file = Deno.makeTempFileSync();
Deno.writeFileSync(file, new TextEncoder().encode("Hello World"));
Deno.truncateSync(file, 7);
const data = Deno.readFileSync(file);
console.log(new TextDecoder().decode(data));

Requires allow-write permission.

Implementation

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