import { FileHandle } from 'node:fs/promises'; /** * Python tempfile module for TypeScript * * Provides async functions for creating temporary files and directories. * All filesystem operations use the async fs/promises API. * * @see {@link https://docs.python.org/3/library/tempfile.html | Python tempfile documentation} * @module */ /** * Return the default directory for temporary files. * * @returns The temporary directory path */ declare function gettempdir(): string; /** * Generate a unique temporary file path (but don't create the file). * * Note: This is deprecated in Python but still useful in some cases. * Consider using mkstemp() or NamedTemporaryFile() instead. * * @param suffix - Optional suffix for the filename * @param prefix - Optional prefix for the filename (default: "tmp") * @param dir - Optional directory (default: system temp dir) * @returns Path to the temporary file */ declare function mktemp(suffix?: string, prefix?: string, dir?: string): string; /** * Create a temporary file and return a tuple of (handle, path). * * @param suffix - Optional suffix for the filename * @param prefix - Optional prefix for the filename (default: "tmp") * @param dir - Optional directory (default: system temp dir) * @param text - If true, open in text mode (default: false) * @returns Promise of tuple [FileHandle, path] * * @example * ```typescript * const [handle, path] = await mkstemp(".txt", "myapp-") * await handle.write(Buffer.from("data")) * await handle.close() * ``` */ declare function mkstemp(suffix?: string, prefix?: string, dir?: string, _text?: boolean): Promise<[FileHandle, string]>; /** * Create a temporary directory and return its path. * * @param suffix - Optional suffix for the directory name * @param prefix - Optional prefix for the directory name (default: "tmp") * @param dir - Optional parent directory (default: system temp dir) * @returns Promise of path to the created directory * * @example * ```typescript * const dir = await mkdtemp("", "myapp-") * // Use directory... * await rm(dir, { recursive: true }) * ``` */ declare function mkdtemp(suffix?: string, prefix?: string, dir?: string): Promise; /** * A named temporary file with async operations. * * Use the static `create()` method to instantiate (constructors cannot be async). * * @example * ```typescript * const tmp = await NamedTemporaryFile.create({ suffix: ".txt" }) * await tmp.write("hello world") * await tmp.close() // File is deleted if deleteOnClose is true * ``` */ declare class NamedTemporaryFile { /** The file handle */ readonly handle: FileHandle; /** The file path */ readonly name: string; /** Whether to delete the file on close */ readonly deleteOnClose: boolean; private _closed; private constructor(); /** * Create a new NamedTemporaryFile. */ static create(options?: { suffix?: string; prefix?: string; dir?: string; delete?: boolean; mode?: string; }): Promise; /** * Write data to the file. */ write(data: string | Uint8Array): Promise; /** * Read data from the file. */ read(size?: number): Promise; /** * Seek to a position in the file. */ seek(_offset: number, _whence?: number): void; /** * Flush the file buffer. */ flush(): Promise; /** * Close the file. */ close(): Promise; /** * Check if the file is closed. */ get closed(): boolean; } /** * A temporary directory that cleans itself up. * * Use the static `create()` method to instantiate (constructors cannot be async). * * @example * ```typescript * const tmp = await TemporaryDirectory.create({ prefix: "myapp-" }) * // Use tmp.name as directory path... * await tmp.cleanup() // Removes directory and contents * ``` */ declare class TemporaryDirectory { /** The directory path */ readonly name: string; private _cleaned; private constructor(); /** * Create a new TemporaryDirectory. */ static create(options?: { suffix?: string; prefix?: string; dir?: string; }): Promise; /** * Remove the temporary directory and its contents. */ cleanup(): Promise; } /** * Create a temporary file that is automatically deleted when closed. * * @param options - Options for creating the file * @returns Promise of NamedTemporaryFile object */ declare function namedTemporaryFile(options?: { suffix?: string; prefix?: string; dir?: string; delete?: boolean; mode?: string; }): Promise; /** * Create a temporary directory that is automatically cleaned up. * * @param options - Options for creating the directory * @returns Promise of TemporaryDirectory object */ declare function temporaryDirectory(options?: { suffix?: string; prefix?: string; dir?: string; }): Promise; /** * Return the name of the file used to store temporary file names. * This is platform-specific and may not exist on all systems. */ declare function gettempprefix(): string; type tempfileModule_NamedTemporaryFile = NamedTemporaryFile; declare const tempfileModule_NamedTemporaryFile: typeof NamedTemporaryFile; type tempfileModule_TemporaryDirectory = TemporaryDirectory; declare const tempfileModule_TemporaryDirectory: typeof TemporaryDirectory; declare const tempfileModule_gettempdir: typeof gettempdir; declare const tempfileModule_gettempprefix: typeof gettempprefix; declare const tempfileModule_mkdtemp: typeof mkdtemp; declare const tempfileModule_mkstemp: typeof mkstemp; declare const tempfileModule_mktemp: typeof mktemp; declare const tempfileModule_namedTemporaryFile: typeof namedTemporaryFile; declare const tempfileModule_temporaryDirectory: typeof temporaryDirectory; declare namespace tempfileModule { export { tempfileModule_NamedTemporaryFile as NamedTemporaryFile, tempfileModule_TemporaryDirectory as TemporaryDirectory, tempfileModule_gettempdir as gettempdir, tempfileModule_gettempprefix as gettempprefix, tempfileModule_mkdtemp as mkdtemp, tempfileModule_mkstemp as mkstemp, tempfileModule_mktemp as mktemp, tempfileModule_namedTemporaryFile as namedTemporaryFile, tempfileModule_temporaryDirectory as temporaryDirectory }; } export { NamedTemporaryFile as N, TemporaryDirectory as T, gettempprefix as a, mkstemp as b, mktemp as c, temporaryDirectory as d, gettempdir as g, mkdtemp as m, namedTemporaryFile as n, tempfileModule as t };