import { AsyncIOResult, AsyncVoidIOResult } from "happy-rusty"; import { AppendOptions, CopyOptions, DirEntry, DownloadFileTempResponse, DownloadRequestInit, ExistsOptions, MoveOptions, ReadDirOptions, ReadFileContent, ReadOptions, TempOptions, UnzipFromUrlRequestInit, UploadRequestInit, WriteFileContent, WriteOptions, ZipFromUrlRequestInit, ZipOptions } from "./shared.cjs"; import { FetchTask } from "@happy-ts/fetch-t"; //#region src/async/archive/unzip-stream.d.ts /** * Unzip a zip file to a directory using streaming decompression. * Equivalent to `unzip -o -d ` * * This function processes the zip file incrementally, minimizing memory usage. * Recommended for large files (>10MB). For small files, consider using {@link unzip} instead. * * Entries that would be written outside of `destDir` (zip-slip) fail the whole * operation instead of being extracted. * * Use [fflate](https://github.com/101arrowz/fflate) as the unzip backend. * * @param zipFilePath - Zip file path. * @param destDir - The directory to unzip to. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the zip file was successfully unzipped. * @since 2.0.0 * @see {@link unzip} for batch version (faster for small files) * @see {@link zipStream} for the reverse operation * @example * ```typescript * (await unzipStream('/downloads/large-archive.zip', '/extracted')) * .inspect(() => console.log('Unzipped successfully')); * ``` */ export declare function unzipStream(zipFilePath: string, destDir: string): AsyncVoidIOResult; /** * Unzip a remote zip file to a directory using streaming decompression. * Equivalent to `unzip -o -d ` * * This function processes the zip file incrementally, minimizing memory usage. * Recommended for large files (>10MB). For small files, consider using {@link unzipFromUrl} instead. * * Use [fflate](https://github.com/101arrowz/fflate) as the unzip backend. * * This API is built on `@happy-ts/fetch-t` for downloading the zip file. * `options` supports `timeout` and `onProgress` options. * * @param zipFileUrl - Zip file url. * @param destDir - The directory to unzip to. * @param requestInit - Optional request options. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the zip file was successfully unzipped. * @since 2.0.0 * @see {@link unzipFromUrl} for batch version (faster for small files) * @see {@link zipStreamFromUrl} for the reverse operation * @example * ```typescript * (await unzipStreamFromUrl('https://example.com/large-archive.zip', '/extracted')) * .inspect(() => console.log('Remote zip file unzipped successfully')); * * // With timeout * (await unzipStreamFromUrl('https://example.com/archive.zip', '/extracted', { timeout: 30000 })) * .inspect(() => console.log('Remote zip file unzipped successfully')); * ``` */ export declare function unzipStreamFromUrl(zipFileUrl: string | URL, destDir: string, requestInit?: UnzipFromUrlRequestInit): AsyncVoidIOResult; //#endregion //#region src/async/archive/unzip.d.ts /** * Unzip a zip file to a directory using batch decompression. * Equivalent to `unzip -o -d ` * * This function loads the entire zip file into memory before decompression. * Faster for small files (<5MB). For large files, consider using {@link unzipStream} instead. * * Entries that would be written outside of `destDir` (zip-slip) fail the whole * operation instead of being extracted. * * Use [fflate](https://github.com/101arrowz/fflate) as the unzip backend. * * @param zipFilePath - Zip file path. * @param destDir - The directory to unzip to. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the zip file was successfully unzipped. * @since 1.6.0 * @see {@link unzipSync} for synchronous version * @see {@link unzipStream} for streaming version (better for large files) * @see {@link zip} for the reverse operation * @example * ```typescript * (await unzip('/downloads/archive.zip', '/extracted')) * .inspect(() => console.log('Unzipped successfully')); * ``` */ export declare function unzip(zipFilePath: string, destDir: string): AsyncVoidIOResult; /** * Unzip a remote zip file to a directory using batch decompression. * Equivalent to `unzip -o -d ` * * This function loads the entire zip file into memory before decompression. * Faster for small files (<5MB). For large files, consider using {@link unzipStreamFromUrl} instead. * * Use [fflate](https://github.com/101arrowz/fflate) as the unzip backend. * * This API is built on `@happy-ts/fetch-t` for downloading the zip file. * `options` supports `timeout` and `onProgress` options. * * @param zipFileUrl - Zip file url. * @param destDir - The directory to unzip to. * @param requestInit - Optional request options. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the zip file was successfully unzipped. * @since 1.7.0 * @see {@link unzipStreamFromUrl} for streaming version (better for large files) * @see {@link zipFromUrl} for the reverse operation * @example * ```typescript * (await unzipFromUrl('https://example.com/archive.zip', '/extracted')) * .inspect(() => console.log('Remote zip file unzipped successfully')); * * // With timeout * (await unzipFromUrl('https://example.com/archive.zip', '/extracted', { timeout: 5000 })) * .inspect(() => console.log('Remote zip file unzipped successfully')); * ``` */ export declare function unzipFromUrl(zipFileUrl: string | URL, destDir: string, requestInit?: UnzipFromUrlRequestInit): AsyncVoidIOResult; //#endregion //#region src/async/archive/zip-stream.d.ts /** * Zip a file or directory using streaming compression. * Equivalent to `zip -r `. * * This function processes files sequentially with streaming read/write, * minimizing memory usage. Recommended for large directories or files. * For better speed with small files, consider using {@link zip} instead. * * Use [fflate](https://github.com/101arrowz/fflate) as the zip backend. * * @param sourcePath - The path to be zipped. * @param zipFilePath - The path to the zip file. * @param options - Options of zip. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the source was successfully zipped. * @since 2.0.0 * @see {@link zip} for batch version (faster for small files) * @see {@link unzipStream} for the reverse operation * @example * ```typescript * // Stream zip a large directory * (await zipStream('/large-documents', '/backups/documents.zip')) * .inspect(() => console.log('Directory zipped successfully')); * ``` */ export declare function zipStream(sourcePath: string, zipFilePath: string, options?: ZipOptions): AsyncVoidIOResult; /** * Zip a remote file using streaming compression. * * This function downloads and compresses the file in a streaming manner, * minimizing memory usage. Recommended for large remote files. * For small files, consider using {@link zipFromUrl} instead. * * Use [fflate](https://github.com/101arrowz/fflate) as the zip backend. * * This API is built on `@happy-ts/fetch-t` for downloading the source. * `requestInit` supports `timeout`, `onProgress`, and `filename` via {@link ZipFromUrlRequestInit}. * * @param sourceUrl - The url to be zipped. * @param zipFilePath - The path to the zip file. * @param requestInit - Optional request initialization parameters. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the source was successfully zipped. * @since 2.0.0 * @see {@link zipFromUrl} for batch version (faster for small files) * @see {@link unzipStreamFromUrl} for the reverse operation * @example * ```typescript * // Stream zip a large remote file * (await zipStreamFromUrl('https://example.com/large-file.bin', '/backups/file.zip')) * .inspect(() => console.log('Remote file zipped successfully')); * ``` */ export declare function zipStreamFromUrl(sourceUrl: string | URL, zipFilePath: string, requestInit?: ZipFromUrlRequestInit): AsyncVoidIOResult; //#endregion //#region src/async/archive/zip.d.ts /** * Zip a file or directory and write to a zip file. * Equivalent to `zip -r `. * * Use [fflate](https://github.com/101arrowz/fflate) as the zip backend. * @param sourcePath - The path to be zipped. * @param zipFilePath - The path to the zip file. * @param options - Options of zip. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the source was successfully zipped. * @since 1.6.0 * @see {@link zipSync} for synchronous version * @see {@link zipStream} for streaming version (better for large files) * @see {@link unzip} for the reverse operation * @example * ```typescript * // Zip a directory to a file * (await zip('/documents', '/backups/documents.zip')) * .inspect(() => console.log('Directory zipped successfully')); * ``` */ export declare function zip(sourcePath: string, zipFilePath: string, options?: ZipOptions): AsyncVoidIOResult; /** * Zip a file or directory and return the zip file data. * Equivalent to `zip -r `. * * Use [fflate](https://github.com/101arrowz/fflate) as the zip backend. * @param sourcePath - The path to be zipped. * @param options - Options of zip. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the source was successfully zipped. * @since 1.6.0 * @see {@link zipSync} for synchronous version * @see {@link zipStream} for streaming version (better for large files) * @see {@link unzip} for the reverse operation * @example * ```typescript * // Zip a directory and get the data * (await zip('/documents')) * .inspect(zipData => console.log(`Zip size: ${ zipData.byteLength } bytes`)); * ``` */ export declare function zip(sourcePath: string, options?: ZipOptions): AsyncIOResult>; /** * Zip a remote file and write to a zip file. * * Use [fflate](https://github.com/101arrowz/fflate) as the zip backend. * * This API is built on `@happy-ts/fetch-t` for downloading the source. * `requestInit` supports `timeout`, `onProgress`, and `filename` via {@link ZipFromUrlRequestInit}. * * @param sourceUrl - The url to be zipped. * @param zipFilePath - The path to the zip file. * @param requestInit - Optional request initialization parameters. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the source was successfully zipped. * @since 1.7.0 * @see {@link zipStreamFromUrl} for streaming version (better for large files) * @see {@link unzipFromUrl} for the reverse operation * @example * ```typescript * // Zip a remote file to a local zip file * (await zipFromUrl('https://example.com/file.txt', '/backups/file.zip')) * .inspect(() => console.log('Remote file zipped successfully')); * ``` */ export declare function zipFromUrl(sourceUrl: string | URL, zipFilePath: string, requestInit?: ZipFromUrlRequestInit): AsyncVoidIOResult; /** * Zip a remote file and return the zip file data. * * Use [fflate](https://github.com/101arrowz/fflate) as the zip backend. * * This API is built on `@happy-ts/fetch-t` for downloading the source. * `requestInit` supports `timeout`, `onProgress`, and `filename` via {@link ZipFromUrlRequestInit}. * * @param sourceUrl - The url to be zipped. * @param requestInit - Optional request initialization parameters. * @returns A promise that resolves to an `AsyncIOResult` indicating whether the source was successfully zipped. * @since 1.7.0 * @see {@link zipStreamFromUrl} for streaming version (better for large files) * @see {@link unzipFromUrl} for the reverse operation * @example * ```typescript * // Zip a remote file and get the data * (await zipFromUrl('https://example.com/file.txt')) * .inspect(zipData => console.log(`Zip size: ${ zipData.byteLength } bytes`)); * ``` */ export declare function zipFromUrl(sourceUrl: string | URL, requestInit?: ZipFromUrlRequestInit): AsyncIOResult>; //#endregion //#region src/async/core/create.d.ts /** * Creates a new empty file at the specified path, similar to the `touch` command. * If the file already exists, this operation succeeds without modifying it. * Parent directories are created automatically if they don't exist. * * **Note:** For temporary files, use {@link mkTemp} instead, which provides * automatic unique naming and integrates with {@link pruneTemp} for cleanup. * * @param filePath - The absolute path of the file to create. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.7.0 * @see {@link createFileSync} for synchronous version * @see {@link mkTemp} for creating temporary files * @see {@link writeFile} for creating files with content * @example * ```typescript * (await createFile('/path/to/file.txt')) * .inspect(() => console.log('File created')); * ``` */ export declare function createFile(filePath: string): AsyncVoidIOResult; /** * Creates a new directory at the specified path, similar to `mkdir -p`. * Creates all necessary parent directories if they don't exist. * * **Note:** For temporary directories, use {@link mkTemp} with `{ isDirectory: true }` instead, * which provides automatic unique naming and integrates with temporary file management. * * @param dirPath - The absolute path where the directory will be created. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.0.0 * @see {@link mkdirSync} for synchronous version * @see {@link emptyDir} for creating or emptying a directory * @see {@link mkTemp} for creating temporary directories * @example * ```typescript * (await mkdir('/path/to/new/directory')) * .inspect(() => console.log('Directory created')); * ``` */ export declare function mkdir(dirPath: string): AsyncVoidIOResult; //#endregion //#region src/async/core/read.d.ts /** * Reads the contents of a directory at the specified path. * * @param dirPath - The path of the directory to read. * @param options - Options of readdir. * @returns A promise that resolves to an `AsyncIOResult` containing an async iterable iterator over the entries of the directory. * @since 1.0.0 * @see {@link readDirSync} for synchronous version * @example * ```typescript * // List directory contents * (await readDir('/documents')) * .inspect(async entries => { * for await (const entry of entries) { * console.log(entry.path, entry.handle.kind); * } * }); * * // List recursively * await readDir('/documents', { recursive: true }); * ``` */ export declare function readDir(dirPath: string, options?: ReadDirOptions): AsyncIOResult>; /** * Reads the content of a file at the specified path as a File. * * @param filePath - The path of the file to read. * @param options - Read options specifying the 'blob' encoding. * @returns A promise that resolves to an `AsyncIOResult` containing the file content as a File. * @since 1.0.0 * @see {@link readFileSync} for synchronous version * @see {@link readBlobFile} convenience wrapper * @example * ```typescript * (await readFile('/path/to/file.txt', { encoding: 'blob' })) * .inspect(file => console.log(file.name, file.size, file.type)); * ``` */ export declare function readFile(filePath: string, options: ReadOptions & { encoding: 'blob'; }): AsyncIOResult; /** * Reads the content of a file at the specified path as a string. * * @param filePath - The path of the file to read. * @param options - Read options specifying the 'utf8' encoding. * @returns A promise that resolves to an `AsyncIOResult` containing the file content as a string. * @since 1.0.0 * @see {@link readFileSync} for synchronous version * @see {@link readTextFile} convenience wrapper * @example * ```typescript * (await readFile('/path/to/file.txt', { encoding: 'utf8' })) * .inspect(content => console.log(content)); * ``` */ export declare function readFile(filePath: string, options: ReadOptions & { encoding: 'utf8'; }): AsyncIOResult; /** * Reads the content of a file at the specified path as a readable stream. * Useful for processing large files without loading them entirely into memory. * * @param filePath - The path of the file to read. * @param options - Read options specifying the 'stream' encoding. * @returns A promise that resolves to an `AsyncIOResult` containing a `ReadableStream`. * @since 1.0.0 * @see {@link readFileSync} for synchronous version (bytes only) * @example * ```typescript * (await readFile('/path/to/large-file.bin', { encoding: 'stream' })) * .inspect(async stream => { * const reader = stream.getReader(); * while (true) { * const { done, value } = await reader.read(); * if (done) break; * console.log('Received chunk:', value.length, 'bytes'); * } * }); * ``` */ export declare function readFile(filePath: string, options: ReadOptions & { encoding: 'stream'; }): AsyncIOResult>>; /** * Reads the content of a file at the specified path as a Uint8Array (default). * * @param filePath - The path of the file to read. * @param options - Optional read options. Defaults to 'bytes' encoding. * @returns A promise that resolves to an `AsyncIOResult` containing the file content as a Uint8Array. * @since 1.0.0 * @see {@link readFileSync} for synchronous version * @example * ```typescript * (await readFile('/path/to/file.bin')) * .inspect(bytes => console.log('First byte:', bytes[0])); * ``` */ export declare function readFile(filePath: string, options?: ReadOptions & { encoding?: 'bytes'; }): AsyncIOResult>; /** * Reads the content of a file at the specified path with the specified options. * This overload accepts any ReadOptions and returns the union of all possible content types. * Useful when the encoding is determined at runtime. * * @param filePath - The path of the file to read. * @param options - Optional read options. * @returns A promise that resolves to an `AsyncIOResult` containing the file content. * @since 1.0.0 * @see {@link readFileSync} for synchronous version * @example * ```typescript * // When encoding is dynamic * const encoding = getUserPreference(); // 'utf8' | 'bytes' | ... * (await readFile('/path/to/file.txt', { encoding })) * .inspect(content => { * // content type is ReadFileContent (union type) * if (typeof content === 'string') { * console.log('Text:', content); * } else if (content instanceof Uint8Array) { * console.log('Bytes:', content.length); * } * }); * ``` */ export declare function readFile(filePath: string, options?: ReadOptions): AsyncIOResult; //#endregion //#region src/async/core/remove.d.ts /** * Removes a file or directory at the specified path, similar to `rm -rf`. * If the path doesn't exist, the operation succeeds silently. * * @param path - The absolute path of the file or directory to remove. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.0.0 * @see {@link removeSync} for synchronous version * @see {@link emptyDir} for emptying a directory without removing it * @see {@link deleteTemp} for removing the temporary directory * @example * ```typescript * (await remove('/path/to/file-or-directory')) * .inspect(() => console.log('Removed successfully')); * ``` */ export declare function remove(path: string): AsyncVoidIOResult; //#endregion //#region src/async/core/stat.d.ts /** * Retrieves the `FileSystemHandle` for a file or directory at the specified path. * Can be used to check the type (file or directory) and access metadata. * * @param path - The absolute path of the file or directory. * @returns A promise that resolves to an `AsyncIOResult` containing the `FileSystemHandle`. * @since 1.0.0 * @see {@link statSync} for synchronous version * @see {@link exists} for checking existence without getting the handle * @see {@link isFileHandle} for checking handle type * @see {@link isDirectoryHandle} for checking handle type * @example * ```typescript * (await stat('/path/to/entry')) * .inspect(handle => console.log(`Kind: ${ handle.kind }, Name: ${ handle.name }`)); * ``` */ export declare function stat(path: string): AsyncIOResult; //#endregion //#region src/async/core/truncate.d.ts /** * 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`. * * @param filePath - The absolute path of the file to truncate. * @param len - The target size in bytes. Must be a non-negative integer. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 2.2.0 * @see {@link truncateSync} for synchronous version * @example * ```typescript * 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" * ``` */ export declare function truncate(filePath: string, len: number): AsyncVoidIOResult; //#endregion //#region src/async/core/write.d.ts /** * Writes content to a file at the specified path. * Creates the file and parent directories if they don't exist (unless `create: false`). * * Overwriting inside a Worker is written to a temporary file in `/tmp` first and moved into * place on success, so an interrupted write leaves the previous content untouched. The main * thread's `createWritable` writes a swap file instead and needs no temp file. Appending * always writes in place. * * @param filePath - The absolute path of the file to write to. * @param contents - The content to write (string, ArrayBuffer, TypedArray, Blob, or ReadableStream). * @param options - Optional write options. * @param options.create - Whether to create the file if it doesn't exist. Default: `true`. * @param options.append - Whether to append to the file instead of overwriting. Default: `false`. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.0.0 * @see {@link writeFileSync} for synchronous version * @see {@link appendFile} for appending to files * @see {@link writeJsonFile} for writing JSON data * @example * ```typescript * // Write string content * await writeFile('/path/to/file.txt', 'Hello, World!'); * * // Write binary content * await writeFile('/path/to/file.bin', new Uint8Array([1, 2, 3])); * * // Append to existing file * await writeFile('/path/to/file.txt', '\nMore content', { append: true }); * ``` */ export declare function writeFile(filePath: string, contents: WriteFileContent, options?: WriteOptions): AsyncVoidIOResult; /** * Opens a file and returns a writable stream for writing contents. * Useful for writing large files without loading them entirely into memory. * The caller is responsible for closing the stream when done. * * @param filePath - The absolute path of the file to write. * @param options - Optional write options. * @returns A promise that resolves to an `AsyncIOResult` containing a `FileSystemWritableFileStream`. * @since 1.0.0 * @see {@link writeFile} for general file writing * @example * ```typescript * (await openWritableFileStream('/path/to/large-file.bin')) * .inspect(async stream => { * try { * await stream.write(new Uint8Array([1, 2, 3])); * await stream.write(new Uint8Array([4, 5, 6])); * } finally { * await stream.close(); * } * }); * ``` */ export declare function openWritableFileStream(filePath: string, options?: WriteOptions): AsyncIOResult; //#endregion //#region src/async/ext.d.ts /** * Appends content to a file at the specified path. * Creates the file if it doesn't exist (unless `create: false` is specified). * * @param filePath - The absolute path of the file to append to. * @param contents - The content to append (string, ArrayBuffer, TypedArray, or Blob). * @param options - Optional append options. * @param options.create - Whether to create the file if it doesn't exist. Default: `true`. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.0.0 * @see {@link writeFile} with `append: true` option * @example * ```typescript * // Append to file, create if doesn't exist (default behavior) * await appendFile('/path/to/log.txt', 'New log entry\n'); * * // Append only if file exists, fail if it doesn't * await appendFile('/path/to/log.txt', 'New log entry\n', { create: false }); * ``` */ export declare function appendFile(filePath: string, contents: WriteFileContent, options?: AppendOptions): AsyncVoidIOResult; /** * Copies a file or directory from one location to another, similar to `cp -r`. * Both source and destination must be of the same type (both files or both directories). * * With `{ overwrite: false }` existing entries are skipped individually while the * rest of the source is still copied (similar to `cp -rn`). * * @param srcPath - The absolute source path. * @param destPath - The absolute destination path. * @param options - Optional copy options. * @param options.overwrite - Whether to overwrite existing files. Default: `true`. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.7.0 * @see {@link move} for moving instead of copying * @example * ```typescript * // Copy a file * await copy('/src/file.txt', '/dest/file.txt'); * * // Copy a directory * await copy('/src/folder', '/dest/folder'); * * // Copy without overwriting existing files * await copy('/src', '/dest', { overwrite: false }); * ``` */ export declare function copy(srcPath: string, destPath: string, options?: CopyOptions): AsyncVoidIOResult; /** * Empties all contents of a directory at the specified path. * If the directory doesn't exist, it will be created. * * @param dirPath - The absolute path of the directory to empty. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.0.9 * @see {@link mkdir} for creating directories * @see {@link remove} for removing directories * @example * ```typescript * await emptyDir('/path/to/directory'); * ``` */ export declare function emptyDir(dirPath: string): AsyncVoidIOResult; /** * Checks whether a file or directory exists at the specified path. * * @param path - The absolute path to check. * @param options - Optional existence options. Set `isDirectory: true` to check for directory, * or `isFile: true` to check for file. Cannot set both to `true`. * @returns A promise that resolves to an `AsyncIOResult` indicating existence. * @since 1.0.0 * @see {@link existsSync} for synchronous version * @see {@link stat} for getting the handle * @example * ```typescript * // Check if path exists (file or directory) * const exists = await exists('/path/to/entry'); * * // Check if path exists and is a file * const isFile = await exists('/path/to/file', { isFile: true }); * * // Check if path exists and is a directory * const isDir = await exists('/path/to/dir', { isDirectory: true }); * ``` */ export declare function exists(path: string, options?: ExistsOptions): AsyncIOResult; /** * Moves a file or directory from one location to another. * Both source and destination must be of the same type (both files or both directories). * * With `{ overwrite: false }` the move follows `mv -n` semantics: when the destination * already exists the operation is a no-op, leaving both the destination and the * source untouched. The source is only removed once the transfer has actually * happened, so a skipped move can never destroy data. * * @param srcPath - The absolute source path. * @param destPath - The absolute destination path. * @param options - Optional move options. * @param options.overwrite - Whether to overwrite existing files. Default: `true`. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.8.0 * @see {@link copy} for copying instead of moving * @example * ```typescript * // Move/rename a file * await move('/old/path/file.txt', '/new/path/file.txt'); * * // Move a directory * await move('/old/folder', '/new/folder'); * * // Keep both files when the destination already exists * await move('/old/file.txt', '/new/file.txt', { overwrite: false }); * ``` */ export declare function move(srcPath: string, destPath: string, options?: MoveOptions): AsyncVoidIOResult; /** * Reads the content of a file as a `File` object (Blob with name). * * @param filePath - The absolute path of the file to read. * @returns A promise that resolves to an `AsyncIOResult` containing the `File` object. * @since 1.0.0 * @see {@link readFile} with `encoding: 'blob'` * @see {@link uploadFile} for uploading files * @example * ```typescript * (await readBlobFile('/path/to/file.txt')) * .inspect(file => console.log(file.name, file.size, file.type)); * ``` */ export declare function readBlobFile(filePath: string): AsyncIOResult; /** * Reads a JSON file and parses its content. * * @template T - The expected type of the parsed JSON object. * @param filePath - The path of the JSON file to read. * @returns A promise that resolves to an `AsyncIOResult` containing the parsed JSON object. * @since 1.8.4 * @see {@link writeJsonFile} for the reverse operation * @see {@link readTextFile} for reading raw text * @example * ```typescript * interface Config { * name: string; * version: number; * } * (await readJsonFile('/config.json')) * .inspect(config => console.log(config.name)); * ``` */ export declare function readJsonFile(filePath: string): AsyncIOResult; /** * Reads a file as a UTF-8 string. * * @param filePath - The absolute path of the file to read. * @returns A promise that resolves to an `AsyncIOResult` containing the file content as a string. * @since 1.0.0 * @see {@link readFile} with `encoding: 'utf8'` * @see {@link readJsonFile} for reading JSON files * @example * ```typescript * (await readTextFile('/path/to/file.txt')) * .inspect(content => console.log(content)); * ``` */ export declare function readTextFile(filePath: string): AsyncIOResult; /** * Writes an object to a file as JSON. * * @template T - The type of the object to write. * @param filePath - The absolute path of the file to write. * @param data - The object to serialize and write. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.0.0 * @see {@link readJsonFile} for the reverse operation * @see {@link writeFile} for writing raw content * @example * ```typescript * const config = { name: 'app', version: 1 }; * (await writeJsonFile('/config.json', config)) * .inspect(() => console.log('Config saved')); * ``` */ export declare function writeJsonFile(filePath: string, data: T): AsyncVoidIOResult; //#endregion //#region src/async/tmp.d.ts /** * Creates a temporary file or directory in the `/tmp` directory. * Uses `crypto.randomUUID()` to generate a unique name. * * @param options - Options for creating the temporary path. * @returns A promise that resolves to an `AsyncIOResult` containing the created path. * @since 1.7.0 * @see {@link generateTempPath} for generating paths without creating * @see {@link deleteTemp} for removing the entire temp directory * @see {@link pruneTemp} for removing expired temp files * @example * ```typescript * // Create a temporary file * (await mkTemp()) * .inspect(path => console.log(path)); // '/tmp/tmp-550e8400-e29b-41d4-a716-446655440000' * * // Create a temporary directory * await mkTemp({ isDirectory: true }); * * // Create with custom basename and extension * await mkTemp({ basename: 'cache', extname: '.json' }); * ``` */ export declare function mkTemp(options?: TempOptions): AsyncIOResult; /** * Deletes the entire temporary directory (`/tmp`) and all its contents. * * **Warning:** When writing a `ReadableStream` to a new file, `writeFile` uses a temporary file * in `/tmp` before moving it to the target path. Calling `deleteTemp()` during such operations * may cause the write to fail. Ensure no stream writes are in progress before calling this function. * * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.7.0 * @see {@link pruneTemp} for selective cleanup * @see {@link remove} for general file/directory removal * @example * ```typescript * (await deleteTemp()) * .inspect(() => console.log('Temporary directory deleted')); * ``` */ export declare function deleteTemp(): AsyncVoidIOResult; /** * Removes expired files from the temporary directory. * Only removes direct children files whose `lastModified` time is before the specified date. * * **Note:** This function only removes files directly under `/tmp`, not subdirectories or their contents. * Use `deleteTemp()` to remove the entire temporary directory including all nested content. * * @param expired - Files modified before this date will be deleted. * @returns A promise that resolves to an `AsyncVoidIOResult` indicating success or failure. * @since 1.7.0 * @see {@link deleteTemp} for removing all temp files * @see {@link mkTemp} for creating temp files * @example * ```typescript * // Remove files older than 24 hours * const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000); * const result = await pruneTemp(yesterday); * ``` */ export declare function pruneTemp(expired: Date): AsyncVoidIOResult; //#endregion //#region src/async/transfer/download.d.ts /** * Downloads a file from a URL and saves it to a temporary file. * The returned response will contain the temporary file path. * * This API is built on `@happy-ts/fetch-t`. * - Supports `timeout` and `onProgress` via {@link DownloadRequestInit} * - Supports `keepEmptyBody` to allow saving empty responses * - Returns an abortable {@link FetchTask} * * @param fileUrl - The URL of the file to download. * @param requestInit - Optional request initialization parameters. * @returns A task that can be aborted and contains the result of the download. * @since 1.0.4 * @see {@link uploadFile} for the reverse operation * @see {@link unzipFromUrl} for downloading and extracting zip files * @example * ```typescript * // Download to a temporary file * const task = downloadFile('https://example.com/file.pdf'); * (await task.result) * .inspect(({ tempFilePath }) => console.log(`File downloaded to: ${ tempFilePath }`)); * ``` */ export declare function downloadFile(fileUrl: string | URL, requestInit?: DownloadRequestInit): FetchTask; /** * Downloads a file from a URL and saves it to the specified path. * * @param fileUrl - The URL of the file to download. * @param filePath - The path where the downloaded file will be saved. * @param requestInit - Optional request initialization parameters. * @returns A task that can be aborted and contains the result of the download. * @since 1.0.4 * @see {@link uploadFile} for the reverse operation * @see {@link unzipFromUrl} for downloading and extracting zip files * @example * ```typescript * // Download to a specific path * const task = downloadFile('https://example.com/file.pdf', '/downloads/file.pdf'); * (await task.result) * .inspect(() => console.log('File downloaded successfully')); * * // Abort the download * task.abort(); * ``` */ export declare function downloadFile(fileUrl: string | URL, filePath: string, requestInit?: DownloadRequestInit): FetchTask; //#endregion //#region src/async/transfer/upload.d.ts /** * Uploads a file from the specified path to a URL. * * This API is built on `@happy-ts/fetch-t`. * - Supports `timeout` and `onProgress` via {@link UploadRequestInit} * - Returns an abortable {@link FetchTask} * * @param filePath - The path of the file to upload. * @param uploadUrl - The URL where the file will be uploaded. * @param requestInit - Optional request initialization parameters. * @returns A task that can be aborted and contains the result of the upload. * @since 1.0.6 * @see {@link downloadFile} for the reverse operation * @see {@link readBlobFile} for reading file as Blob before upload * @example * ```typescript * const task = uploadFile('/documents/report.pdf', 'https://example.com/upload'); * (await task.result) * .inspect(() => console.log('File uploaded successfully')); * * // Abort the upload * task.abort(); * ``` */ export declare function uploadFile(filePath: string, uploadUrl: string | URL, requestInit?: UploadRequestInit): FetchTask; //#endregion //# sourceMappingURL=async.d.cts.map