truncate method

Future<void> truncate([
  1. num? len
])

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 = await Deno.open("my_file.txt", { write: true });
await file.truncate();
file.close();

Truncate part of the file

// if "my_file.txt" contains the text "hello world":
const file = await Deno.open("my_file.txt", { write: true });
await file.truncate(7);
const buf = new Uint8Array(100);
await file.read(buf);
const text = new TextDecoder().decode(buf); // "hello w"
file.close();

Implementation

_i2.Future<void> truncate([_i2.num? len]) =>
    _i3.promiseToFuture(_i3.callMethod(
      this,
      'truncate',
      [len ?? _i6.undefined],
    ));