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

x/deno/cli/tsc/dts/lib.deno.ns.d.ts>Deno.truncateSync

A modern runtime for JavaScript and TypeScript.
Latest
function Deno.truncateSync
allow-write
import { Deno } from "https://deno.land/x/deno@v2.0.4/cli/tsc/dts/lib.deno.ns.d.ts";
const { truncateSync } = Deno;

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.

Parameters

name: string
optional
len: number