Skip to content

truncate

Module @netwiv/api/plugins/fs · Kind Function

import { truncate } from '@netwiv/api/plugins/fs';

Truncates or extends the specified file, to reach the specified len. If len is 0 or not specified, then the entire file contents are truncated.

function truncate(path: string | URL, len?: number | undefined, options?: TruncateOptions | undefined): Promise<void>
import { truncate, readTextFile, writeTextFile, BaseDirectory } from '@netwiv/api/plugins/fs';
// truncate the entire file
await truncate("my_file.txt", 0, { baseDir: BaseDirectory.AppLocalData });
// truncate part of the file
const filePath = "file.txt";
await writeTextFile(filePath, "Hello World", { baseDir: BaseDirectory.AppLocalData });
await truncate(filePath, 7, { baseDir: BaseDirectory.AppLocalData });
const data = await readTextFile(filePath, { baseDir: BaseDirectory.AppLocalData });
console.log(data); // "Hello W"

Upstream since 2.0.0


Descriptions come from the pinned @tauri-apps/plugin-fs@2.5.2 declarations (MIT OR Apache-2.0); imports are shown with @netwiv/api paths.