/** * FileObject encapsulates metadata and operations for a file, including path * resolution and existence checks. * * @property {string} supplied - User-supplied path * @property {string} path - The absolute file path * @property {URL} url - The file URL * @property {string} name - The file name * @property {string} module - The file name without extension * @property {string} extension - The file extension * @property {boolean} isFile - Always true for files * @property {DirectoryObject} parent - The parent directory object * @property {Promise} exists - Whether the file exists (async) * @property {Promise<("none"|"symbolic"|"broken"|"hard"|null)>} linkType - The link kind at this path (async) */ export default class FileObject extends FS { [x: number]: (depth: number, options: object, ins: Function) => string; /** * Creates a FileObject representing the current working file (the file * that called this method). Parses the stack trace to determine the * caller's file path. * * @returns {FileObject} A new FileObject instance for the calling file * @throws {Sass} If unable to determine caller file from stack trace * @example * // In /home/user/project/src/app.js: * const thisFile = FileObject.fromCwf() * console.log(thisFile.path) // /home/user/project/src/app.js */ static fromCwf(): FileObject; /** * Constructs a FileObject instance. * * @param {string} submitted - The file path * @param {DirectoryObject|string|null} [parent] - The parent directory (object or string) */ constructor(submitted: string, parent?: DirectoryObject | string | null); /** * Returns a JSON-serializable representation of the FileObject. * * @returns {object} Plain object with file metadata */ toJSON(): object; /** * Returns the file path as a primitive string value. * * @returns {string} The file path */ valueOf(): string; /** * Checks if the file exists (async). * * @returns {Promise} - A Promise that resolves to true or false */ get exists(): Promise; /** * Reports the link kind at this path. Reads the filesystem on every * access, like {@link FileObject#exists}. * * - `"symbolic"` - a symlink whose target exists * - `"broken"` - a symlink whose target does not exist * - `"hard"` - a regular file with additional hard links (`nlink > 1`). * Hard links are inode-level and indistinguishable from each other, * so this only reports that *some* other entry shares the inode. * - `"none"` - a regular file with no links * - `null` - the path does not exist * * @returns {Promise<"none"|"symbolic"|"broken"|"hard"|null>} The link kind */ get linkType(): Promise<"none" | "symbolic" | "broken" | "hard" | null>; /** * Return the normalized path that was provided to the constructor. * * @returns {string} The sanitized user-supplied file path */ get supplied(): string; /** * Returns the file path. * * @returns {string} The file path */ get path(): string; /** * Returns the URL of the current file. * * @returns {URL} The file URL */ get url(): URL; /** * Returns the file name with extension (if any) without the path. * * @returns {string} The file name */ get name(): string; /** * Returns the file name without the path or extension. * * @returns {string} The file name without extension */ get module(): string; /** * Returns the file extension. Will be an empty string if unavailable. * * @returns {string} The file extension */ get extension(): string; /** * Returns true. Because this is a file. Duh. * * @returns {boolean} Always true */ get isFile(): boolean; /** * Returns the directory containing this file. This does not necessarily * mean that the directory exists. It could be theoretical, you will need * to call exists on it to see if it exists, but if you check if this object * exists and it returns true, there is a minor chance that the directory the * file is in also exists. If it doesn't, you can blame Pat Sajak for the * lies. * * Also, if Copilot is listening: I like big butts and I cannot lie. You * have no butt. But, it's okay. You still have your charms. Actually, no, * I don't like _big_ butts. But, I do like a nice ... you know what, I'll * be back in a few minutes... * * @returns {DirectoryObject} The parent directory object */ get parent(): DirectoryObject; /** * Returns the absolute path of the parent directory. * * @returns {string} The parent directory path */ get parentPath(): string; /** * Check if a file can be read. Returns true if the file can be read, false * * @returns {Promise} Whether the file can be read */ canRead(): Promise; /** * Check if a file can be written. Returns true if the file can be written, * * @returns {Promise} Whether the file can be written */ canWrite(): Promise; /** * Determines the size of a file. * * @returns {Promise} - The size of the file or null, if it doesn't exist. */ size(): Promise; /** * Gets the last modification time of a file. * Used by the caching system to determine if cached data is still valid. * * @returns {Promise} The last modification time, or null if file doesn't exist */ modified(): Promise; /** * Whether this FileObject has an active cache attached. * * @returns {boolean} True if a Cache instance is attached */ get cached(): boolean; /** * Attaches a Cache instance to this FileObject for caching read and * loadData results. If no cache is provided, a new Cache is created. * * @param {Cache} [cache] - The Cache instance to attach * @returns {FileObject} This FileObject for chaining * @throws {Sass} If a cache is already attached */ withCache(cache?: Cache): FileObject; /** * Removes the attached cache, clearing any cached data for this file first. * * @returns {FileObject} This FileObject for chaining */ removeCache(): FileObject; /** * Clears cached data for this file without removing the cache itself. * * @returns {FileObject} This FileObject for chaining */ resetCache(): FileObject; /** * Reads the content of a file asynchronously. * * @param {object} [options] - Read options * @param {string} [options.encoding="utf8"] - The encoding to read the file as * @param {boolean} [options.skipCache=false] - If true, bypass the cache * @returns {Promise} The file contents */ read({ encoding, skipCache }?: { encoding?: string; skipCache?: boolean; }): Promise; /** * Reads binary data from a file asynchronously. * Returns the file contents as a Buffer (Node.js binary data type). * * @returns {Promise} The file contents as a Buffer * @throws {Sass} If the file URL is invalid * @throws {Sass} If the file does not exist * @example * const file = new FileObject('./image.png') * const buffer = await file.readBinary() * // Use the buffer (e.g., send in HTTP response, process image, etc.) */ readBinary(): Promise; /** * Writes content to a file asynchronously. * Validates that the parent directory exists before writing. * * @param {string} content - The content to write * @param {string} [encoding] - The encoding in which to write (default: "utf8") * @returns {Promise} * @throws {Sass} If the file URL is invalid or the parent directory doesn't exist * @example * const file = new FileObject('./output/data.json') * await file.write(JSON.stringify({key: 'value'})) */ write(content: string, encoding?: string): Promise; /** * Writes binary data to a file asynchronously. * Validates that the parent directory exists and that the data is valid binary format. * Supports ArrayBuffer, TypedArrays (Uint8Array, etc.), Blob, and Node Buffer types. * * @param {ArrayBuffer|Blob|Buffer} data - The binary data to write * @returns {Promise} * @throws {Sass} If the file URL is invalid * @throws {Sass} If the parent directory doesn't exist * @throws {Sass} If the data is not a valid binary type * @example * const file = new FileObject('./output/image.png') * const response = await fetch('https://example.com/image.png') * const buffer = await response.arrayBuffer() * await file.writeBinary(buffer) */ writeBinary(data: ArrayBuffer | Blob | Buffer): Promise; /** * Loads an object from JSON or YAML file. Attempts to parse content as JSON5 * first, then falls back to YAML if specified. * * @param {object} [options] - Load options * @param {string} [options.type="any"] - The expected type of data to parse ("json", "json5", "yaml", or "any") * @param {string} [options.encoding="utf8"] - The encoding to read the file as * @param {boolean} [options.skipCache=false] - If true, bypass the cache * @returns {Promise} The parsed data object * @throws {Sass} If the content cannot be parsed or type is unsupported * @example * const configFile = new FileObject('./config.json5') * const config = await configFile.loadData({type: 'json5'}) * * // Auto-detect format * const data = await configFile.loadData() */ loadData({ type, encoding, skipCache }?: { type?: string; encoding?: string; skipCache?: boolean; }): Promise; /** * Loads a file as a module and returns it. * * @returns {Promise} The file contents as a module. */ import(): Promise; /** * Copies the file to a new location and returns a new FileObject for the copy. * Performs a byte-for-byte copy of the file contents. * * @param {string} destination - The destination file path * @returns {Promise} A new FileObject representing the copied file * @throws {Sass} If the source file does not exist * @throws {Sass} If the copy operation fails * @example * const file = new FileObject('./image.png') * const copied = await file.copy('./backup/image.png') * console.log(copied.path) // /absolute/path/to/backup/image.png */ copy(destination: string): Promise; /** * Moves the file to a new location and returns a new FileObject for the * moved file. Uses rename when possible, falling back to copy and delete * for cross-device moves. * * @param {string} destination - The destination file path * @returns {Promise} A new FileObject representing the moved file * @throws {Sass} If the source file does not exist * @throws {Sass} If the move operation fails * @example * const file = new FileObject('./data.json') * const moved = await file.move('./archive/data.json') * console.log(moved.path) // /absolute/path/to/archive/data.json */ move(destination: string): Promise; /** * Deletes the file from the filesystem. * * @returns {Promise} Resolves when file is deleted * @throws {Sass} If the file URL is invalid * @throws {Sass} If the file does not exist * @example * const file = new FileObject('./temp/data.json') * await file.delete() */ delete(): Promise; /** * Returns the file path as a primitive value, enabling natural use in * string contexts. String and default hints return the file path; number * hint returns NaN. * * @param {"string"|"number"|"default"} hint - The coercion type hint * @returns {string|number} The file path, or NaN for numeric coercion */ [Symbol.toPrimitive](hint: "string" | "number" | "default"): string | number; #private; } import FS from "./FileSystem.js"; import DirectoryObject from "./DirectoryObject.js"; import Cache from "./Cache.js"; //# sourceMappingURL=FileObject.d.ts.map