Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/lib.deno.d.ts>Deno.FsFile#truncate

A JavaScript extension package for building strong and modern applications.
Latest
method Deno.FsFile.prototype.truncate
import { Deno } from "https://deno.land/x/ayonli_jsext@v0.9.72/lib.deno.d.ts";
const { FsFile } = Deno;

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

Truncate part of the file

// if "my_file.txt" contains the text "hello world":
using 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"

Parameters

optional
len: number

Returns

Promise<void>