import { IOResult, VoidIOResult } from "happy-rusty"; import { AppendOptions, CopyOptions, DirEntryLike, DirEntrySlim, ExistsOptions, FileSystemHandleLike, MoveOptions, ReadDirSyncOptions, ReadSyncFileContent, ReadSyncOptions, TempOptions, WriteOptions, WriteSyncFileContent, ZipOptions } from "./shared.mjs"; import * as SyncChannel from "./SyncChannel.mjs"; //#region src/sync/ops.d.ts /** * Synchronous version of `createFile`. * Creates a new empty file at the specified path. * * @param filePath - The absolute path of the file to create. * @returns A `VoidIOResult` indicating success or failure. * @see {@link createFile} for the async version. * @since 1.7.0 * @example * ```typescript * createFileSync('/path/to/file.txt') * .inspect(() => console.log('File created')); * ``` */ export declare function createFileSync(filePath: string): VoidIOResult; /** * Synchronous version of `mkdir`. * Creates a directory at the specified path, including any necessary parent directories. * * @param dirPath - The absolute path of the directory to create. * @returns A `VoidIOResult` indicating success or failure. * @see {@link mkdir} for the async version. * @since 1.1.0 * @example * ```typescript * mkdirSync('/path/to/directory') * .inspect(() => console.log('Directory created')); * ``` */ export declare function mkdirSync(dirPath: string): VoidIOResult; /** * Synchronous version of `move`. * Moves a file or directory from one location to another. * * @param srcPath - The source path. * @param destPath - The destination path. * @param options - Optional move options. * @returns A `VoidIOResult` indicating success or failure. * @see {@link move} for the async version. * @since 1.8.0 * @example * ```typescript * moveSync('/old/path/file.txt', '/new/path/file.txt') * .inspect(() => console.log('File moved')); * ``` */ export declare function moveSync(srcPath: string, destPath: string, options?: MoveOptions): VoidIOResult; /** * Synchronous version of `readDir`. * Reads the contents of a directory without file metadata. * * Each entry carries only `path` and `kind`: no per-file `getFile()` lookup is performed * and the response stays small, which is what makes listing a large tree feasible. * Read metadata with {@link statSync} when it is actually needed. * * @param dirPath - The absolute path of the directory to read. * @param options - Read options with `withMetadata: false`. * @returns An `IOResult` containing an array of directory entries without metadata. * @see {@link readDirSync} for the metadata-carrying overload * @since 2.3.0 * @example * ```typescript * readDirSync('/documents', { recursive: true, withMetadata: false }) * .inspect(entries => entries.forEach(entry => console.log(entry.path, entry.kind))); * ``` */ export declare function readDirSync(dirPath: string, options: ReadDirSyncOptions & { withMetadata: false; }): IOResult; /** * Synchronous version of `readDir`. * Reads the contents of a directory. * * **Note:** Returns `DirEntryLike[]` instead of `AsyncIterableIterator` because: * 1. Sync API cannot return async iterators * 2. Native `FileSystemHandle` objects cannot be serialized across threads; * `DirEntryLike` uses `FileSystemHandleLike` which is JSON-serializable * * Pass `{ withMetadata: false }` to skip the per-file metadata lookup and get * `DirEntrySlim[]` instead, which keeps the response small when listing a large tree. * * @param dirPath - The absolute path of the directory to read. * @param options - Optional read options (e.g., recursive). * @returns An `IOResult` containing an array of directory entries. * @see {@link readDir} for the async version. * @since 1.1.0 * @example * ```typescript * readDirSync('/documents') * .inspect(entries => entries.forEach(e => console.log(e.path, e.handle.kind))); * ``` */ export declare function readDirSync(dirPath: string, options?: ReadDirSyncOptions): IOResult; /** * Synchronous version of `readFile`. * Reads the content of a file as a `File` object (blob encoding). * * @param filePath - The absolute path of the file to read. * @param options - Read options with 'blob' encoding. * @returns An `IOResult` containing a `File` object. * @since 1.1.0 * @example * ```typescript * readFileSync('/path/to/file.txt', { encoding: 'blob' }) * .inspect(file => console.log(file.name, file.size)); * ``` */ export declare function readFileSync(filePath: string, options: ReadSyncOptions & { encoding: 'blob'; }): IOResult; /** * Synchronous version of `readFile`. * Reads the content of a file as a string (utf8 encoding). * * @param filePath - The absolute path of the file to read. * @param options - Read options with 'utf8' encoding. * @returns An `IOResult` containing the file content as a string. * @since 1.1.0 * @example * ```typescript * readFileSync('/path/to/file.txt', { encoding: 'utf8' }) * .inspect(content => console.log(content)); * ``` */ export declare function readFileSync(filePath: string, options: ReadSyncOptions & { encoding: 'utf8'; }): IOResult; /** * Synchronous version of `readFile`. * Reads the content of a file as a Uint8Array (default). * * @param filePath - The absolute path of the file to read. * @param options - Optional read options. Defaults to 'bytes' encoding. * @returns An `IOResult` containing the file content as a Uint8Array. * @since 1.1.0 * @example * ```typescript * readFileSync('/path/to/file.bin') * .inspect(bytes => console.log('First byte:', bytes[0])); * ``` */ export declare function readFileSync(filePath: string, options?: ReadSyncOptions & { encoding?: 'bytes'; }): IOResult>; /** * Synchronous version of `readFile`. * Reads the content of a file 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 absolute path of the file to read. * @param options - Optional read options. * @returns An `IOResult` containing the file content. * @see {@link readFile} for the async version. * @since 1.1.0 * @example * ```typescript * // When encoding is dynamic * const encoding = getUserPreference(); // 'utf8' | 'bytes' | ... * readFileSync('/path/to/file.txt', { encoding }) * .inspect(content => { * // content type is ReadSyncFileContent (union type) * if (typeof content === 'string') { * console.log('Text:', content); * } else if (content instanceof Uint8Array) { * console.log('Bytes:', content.length); * } * }); * ``` */ export declare function readFileSync(filePath: string, options?: ReadSyncOptions): IOResult; /** * Synchronous version of `remove`. * Removes a file or directory at the specified path. * * @param path - The absolute path of the file or directory to remove. * @returns A `VoidIOResult` indicating success or failure. * @see {@link remove} for the async version. * @since 1.1.0 * @example * ```typescript * removeSync('/path/to/file-or-directory') * .inspect(() => console.log('Removed successfully')); * ``` */ export declare function removeSync(path: string): VoidIOResult; /** * Synchronous version of `stat`. * Retrieves metadata about a file or directory. * * **Note:** Returns `FileSystemHandleLike` instead of `FileSystemHandle` because * native `FileSystemHandle` objects cannot be serialized across threads. * `FileSystemHandleLike` is a plain object with `name` and `kind` properties. * For file entries, it also includes `size`, `type`, and `lastModified` - * use `isFileHandleLike()` to check and narrow the type. * * @param path - The absolute path to get status for. * @returns An `IOResult` containing a `FileSystemHandleLike` object. * @see {@link stat} for the async version. * @since 1.1.0 * @example * ```typescript * statSync('/path/to/entry') * .inspect(handle => console.log(`Kind: ${ handle.kind }, Name: ${ handle.name }`)); * ``` */ export declare function statSync(path: string): IOResult; /** * Synchronous version of `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`). * * @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 `VoidIOResult` indicating success or failure. * @see {@link truncate} for the async version. * @since 2.2.0 * @example * ```typescript * truncateSync('/log.txt', 5) * .inspect(() => console.log('File truncated')); * ``` */ export declare function truncateSync(filePath: string, len: number): VoidIOResult; /** * Synchronous version of `writeFile`. * Writes content to a file at the specified path. * * @param filePath - The absolute path of the file to write. * @param contents - The content to write (ArrayBuffer, TypedArray, or string). * @param options - Optional write options. * @returns A `VoidIOResult` indicating success or failure. * @see {@link writeFile} for the async version. * @since 1.1.0 * @example * ```typescript * // Write string content * writeFileSync('/path/to/file.txt', 'Hello, World!'); * * // Write binary content * writeFileSync('/path/to/file.bin', new Uint8Array([1, 2, 3])); * ``` */ export declare function writeFileSync(filePath: string, contents: WriteSyncFileContent, options?: WriteOptions): VoidIOResult; /** * Synchronous version of `appendFile`. * Appends content to a file at the specified path. * * @param filePath - The absolute path of the file to append to. * @param contents - The content to append (ArrayBuffer, TypedArray, or string). * @param options - Optional append options. * @param options.create - Whether to create the file if it doesn't exist. Default: `true`. * @returns A `VoidIOResult` indicating success or failure. * @see {@link appendFile} for the async version. * @since 1.1.0 * @example * ```typescript * // Append to file, create if doesn't exist (default behavior) * appendFileSync('/path/to/log.txt', 'New log entry\n'); * * // Append only if file exists, fail if it doesn't * appendFileSync('/path/to/log.txt', 'New log entry\n', { create: false }); * ``` */ export declare function appendFileSync(filePath: string, contents: WriteSyncFileContent, options?: AppendOptions): VoidIOResult; /** * Synchronous version of `copy`. * Copies a file or directory from one location to another. * * @param srcPath - The source path. * @param destPath - The destination path. * @param options - Optional copy options. * @returns A `VoidIOResult` indicating success or failure. * @see {@link copy} for the async version. * @since 1.7.0 * @example * ```typescript * // Copy a file * copySync('/src/file.txt', '/dest/file.txt'); * * // Copy without overwriting * copySync('/src', '/dest', { overwrite: false }); * ``` */ export declare function copySync(srcPath: string, destPath: string, options?: CopyOptions): VoidIOResult; /** * Synchronous version of `emptyDir`. * Removes all contents of a directory. * * @param dirPath - The absolute path of the directory to empty. * @returns A `VoidIOResult` indicating success or failure. * @see {@link emptyDir} for the async version. * @since 1.1.0 * @example * ```typescript * emptyDirSync('/path/to/directory'); * ``` */ export declare function emptyDirSync(dirPath: string): VoidIOResult; /** * Synchronous version of `exists`. * Checks whether a file or directory exists at the specified path. * * @param path - The absolute path to check. * @param options - Optional existence options (e.g., isDirectory, isFile). * @returns An `IOResult` containing `true` if exists, `false` otherwise. * @see {@link exists} for the async version. * @since 1.1.0 * @example * ```typescript * existsSync('/path/to/file') * .inspect(exists => exists && console.log('File exists')); * ``` */ export declare function existsSync(path: string, options?: ExistsOptions): IOResult; /** * Synchronous version of `deleteTemp`. * Deletes the temporary directory and all its contents. * * @returns A `VoidIOResult` indicating success or failure. * @see {@link deleteTemp} for the async version. * @since 1.7.0 * @example * ```typescript * deleteTempSync(); * ``` */ export declare function deleteTempSync(): VoidIOResult; /** * Synchronous version of `mkTemp`. * Creates a temporary file or directory. * * @param options - Optional temp options (e.g., isDirectory, basename, extname). * @returns An `IOResult` containing the temporary path. * @see {@link mkTemp} for the async version. * @since 1.7.0 * @example * ```typescript * mkTempSync({ extname: '.txt' }) * .inspect(path => console.log('Temp file:', path)); * ``` */ export declare function mkTempSync(options?: TempOptions): IOResult; /** * Synchronous version of `pruneTemp`. * Removes expired files from the temporary directory. * * @param expired - Files with lastModified before this date will be removed. * @returns A `VoidIOResult` indicating success or failure. * @see {@link pruneTemp} for the async version. * @since 1.7.0 * @example * ```typescript * // Remove files older than 24 hours * const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000); * pruneTempSync(yesterday); * ``` */ export declare function pruneTempSync(expired: Date): VoidIOResult; /** * Synchronous version of `readBlobFile`. * Reads a file as a `File` object. * * @param filePath - The absolute path of the file to read. * @returns An `IOResult` containing a `File` object. * @see {@link readBlobFile} for the async version. * @since 1.1.0 * @example * ```typescript * readBlobFileSync('/path/to/file.txt') * .inspect(file => console.log(file.name, file.size, file.type)); * ``` */ export declare function readBlobFileSync(filePath: string): IOResult; /** * Synchronous version of `readJsonFile`. * Reads and parses a JSON file. * * @template T - The expected type of the parsed JSON. * @param filePath - The absolute path of the JSON file to read. * @returns An `IOResult` containing the parsed JSON object. * @see {@link readJsonFile} for the async version. * @since 1.8.4 * @example * ```typescript * interface Config { name: string; version: number } * readJsonFileSync('/config.json') * .inspect(config => console.log(config.name)); * ``` */ export declare function readJsonFileSync(filePath: string): IOResult; /** * Synchronous version of `readTextFile`. * Reads a file as a UTF-8 string. * * @param filePath - The absolute path of the file to read. * @returns An `IOResult` containing the file content as a string. * @see {@link readTextFile} for the async version. * @since 1.1.0 * @example * ```typescript * readTextFileSync('/path/to/file.txt') * .inspect(content => console.log(content)); * ``` */ export declare function readTextFileSync(filePath: string): IOResult; /** * Synchronous version of `writeJsonFile`. * 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 `VoidIOResult` indicating success or failure. * @see {@link writeJsonFile} for the async version. * @since 1.1.0 * @example * ```typescript * const config = { name: 'app', version: 1 }; * writeJsonFileSync('/config.json', config); * ``` */ export declare function writeJsonFileSync(filePath: string, data: T): VoidIOResult; /** * Synchronous version of `unzip`. * Extracts a zip file to a directory. * * @param zipFilePath - The path to the zip file. * @param destDir - The directory to unzip to. * @returns A `VoidIOResult` indicating success or failure. * @see {@link unzip} for the async version. * @since 1.6.0 * @example * ```typescript * unzipSync('/downloads/archive.zip', '/extracted'); * ``` */ export declare function unzipSync(zipFilePath: string, destDir: string): VoidIOResult; /** * Synchronous version of `zip`. * Zips a file or directory and writes to a zip file. * * @param sourcePath - The path to zip. * @param zipFilePath - The destination zip file path. * @param options - Optional zip options. * @returns A `VoidIOResult` indicating success or failure. * @see {@link zip} for the async version. * @since 1.6.0 * @example * ```typescript * zipSync('/documents', '/backups/documents.zip'); * ``` */ export declare function zipSync(sourcePath: string, zipFilePath: string, options?: ZipOptions): VoidIOResult; /** * Synchronous version of `zip`. * Zips a file or directory and returns the zip data. * * @param sourcePath - The path to zip. * @param options - Optional zip options. * @returns An `IOResult` containing the zip data as `Uint8Array`. * @see {@link zip} for the async version. * @since 1.6.0 * @example * ```typescript * zipSync('/documents') * .inspect(data => console.log('Zip size:', data.byteLength)); * ``` */ export declare function zipSync(sourcePath: string, options?: ZipOptions): IOResult>; //#endregion export { SyncChannel }; //# sourceMappingURL=sync.d.mts.map