@tauri-apps/plugin-fs - v2.4.1
    Preparing search index...

    Function truncate

    • 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.

      Parameters

      Returns Promise<void>

      import { truncate, readTextFile, writeTextFile, BaseDirectory } from '@tauri-apps/plugin-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"

      2.0.0