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

x/deno/cli/js/lib.deno.ns.d.ts>Deno.truncate

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.truncate
import { Deno } from "https://deno.land/x/deno@v1.0.0/cli/js/lib.deno.ns.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.writeFile(file, new TextEncoder().encode("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>