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

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

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

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

await Deno.truncate("my_file.txt");

Truncate part of the file

const file = await Deno.makeTempFile();
await Deno.writeTextFile(file, "Hello World");
await Deno.truncate(file, 7);
const data = await Deno.readFile(file);
console.log(new TextDecoder().decode(data));  // "Hello W"

Requires allow-write permission.

Parameters

name: string
optional
len: number

Returns

Promise<void>