Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

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

A modern runtime for JavaScript and TypeScript.
Go to Latest
method Deno.FsFile.prototype.truncateSync
import { Deno } from "https://deno.land/x/deno@v1.28.0/cli/dts/lib.deno.ns.d.ts";
const { FsFile } = Deno;

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

Truncate part of the file

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

Parameters

optional
len: number