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
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
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
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
optional
options: FileSystemOptions = [UNSUPPORTED]