Library API
    Preparing search index...

    A utility class for sandboxed file operations within a temporary directory. Prevents path traversal and forces all operations to occur in os.tmpdir().

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    encoding: BufferEncoding = 'utf8'
    tmpDir: string = ...

    Methods

    • Check if a file exists in the temporary directory.

      Parameters

      • file: string

        The filename to check

      Returns Promise<boolean>

      A promise resolving to true if the file exists, false otherwise

      const hasConfig = await File.exist('config.json');
      
    • Read a file's contents from the temporary directory.

      Parameters

      • file: string

        The filename to read

      Returns Promise<string | number | bigint>

      A promise resolving to the file contents (coerced to number/bigint if applicable)

      const content = await File.read('data.txt');
      
    • Remove a file from the temporary directory.

      Parameters

      • file: string

        The filename to remove

      Returns Promise<void>

      A promise resolving when the file is deleted

      await File.remove('temp-data.txt');
      
    • Write content to a file in the temporary directory.

      Parameters

      • file: string

        The filename to write to

      • doc: string | ArrayBufferView<ArrayBufferLike>

        The content to write

      Returns Promise<string | ArrayBufferView<ArrayBufferLike>>

      A promise resolving to the written content

      await File.write('output.json', '{"status":"ok"}');