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.
Signature
Section titled “Signature”function truncate(path: string | URL, len?: number | undefined, options?: TruncateOptions | undefined): Promise<void>Example
Section titled “Example”import { truncate, readTextFile, writeTextFile, BaseDirectory } from '@netwiv/api/plugins/fs';// truncate the entire fileawait truncate("my_file.txt", 0, { baseDir: BaseDirectory.AppLocalData });
// truncate part of the fileconst 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.