truncate
truncate(
path,len?,options?):Promise<void>
Defined in: plugins/fs/guest-js/index.ts:1022
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.
string | URL
number
Promise<void>
import { truncate, readTextFile, writeTextFile, BaseDirectory } from '@tauri-apps/plugin-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"2.0.0
© 2025 Tauri Contributors. CC-BY / MIT