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

x/ayonli_jsext/fs.ts>truncate

A JavaScript extension package for building strong and modern applications.
Latest
function truncate
import { truncate } from "https://deno.land/x/ayonli_jsext@v0.9.72/fs.ts";

Truncates (or extends) the file to reach the specified size. If size is not specified then the entire file contents are truncated.

Examples

Example 1

// with the default storage
import { stat, truncate } from "@ayonli/jsext/fs";

await truncate("/path/to/file.txt", 1024);
const info = await stat("/path/to/file.txt");
console.assert(info.size === 1024);

Example 2

// with a user-selected directory as root (Chromium only)
import { stat, truncate } from "@ayonli/jsext/fs";

const root = await window.showDirectoryPicker();
await truncate("/path/to/file.txt", 1024, { root });
const info = await stat("/path/to/file.txt", { root });
console.assert(info.size === 1024);

Example 3

// truncate the file to zero size
import { stat, truncate } from "@ayonli/jsext/fs";

await truncate("/path/to/file.txt");
const info = await stat("/path/to/file.txt");
console.assert(info.size === 0);

Parameters

target: string | FileSystemFileHandle
optional
size = [UNSUPPORTED]
optional
options: FileSystemOptions = [UNSUPPORTED]

Returns

Promise<void>