happy-opfs
    Preparing search index...

    Function truncate

    • Truncates (resizes) a file to the specified size.

      If len is smaller than the current file size, the file is shortened and the trailing data is discarded. If len is larger, the file is extended with zero bytes (\x00).

      The file must already exist; this operation never creates a new file. Truncating a directory path returns a TypeMismatchError.

      Parameters

      • filePath: string

        The absolute path of the file to truncate.

      • len: number

        The target size in bytes. Must be a non-negative integer.

      Returns AsyncVoidIOResult

      A promise that resolves to an AsyncVoidIOResult indicating success or failure.

      2.2.0

      truncateSync for synchronous version

      await writeFile('/log.txt', 'Hello, World!');
      await truncate('/log.txt', 5); // file now contains "Hello"
      await truncate('/log.txt', 8); // file now contains "Hello\x00\x00\x00"