Path: redb-route/redb.Route.GenericFile/IFileOperations.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.GenericFile/IFileOperations.cs ---- namespace redb.Route.GenericFile; /// /// Abstraction for file system operations. Implementations adapt /// concrete I/O APIs (System.IO, SSH.NET, FluentFTP) to a uniform interface. /// All path operations are protocol-aware (forward-slash for remote, OS-native for local). /// public interface IFileOperations { // ── Enumeration ───────────────────────────────────────────────── /// /// Lists files in the given directory. /// /// Base directory path. /// Whether to recurse into subdirectories. /// Maximum recursion depth (0 = unlimited). /// Minimum depth — files at shallower levels are skipped. /// /// Asked before walking into a subdirectory, with its full path and its path relative to /// ; false skips that subdirectory and everything below it /// without listing it. Null = walk into every subdirectory. The decision belongs here rather /// than in the consumer because skipping the listing is the entire saving. /// /// Cancellation token. /// List of file metadata. Task> ListFilesAsync( string directory, bool recursive, int maxDepth, int minDepth, Func? directoryFilter = null, CancellationToken ct = default); // ── Read ──────────────────────────────────────────────────────── /// Reads the entire file into a byte array. Task ReadAllBytesAsync(string path, CancellationToken ct = default); /// Opens a read stream to the file. Caller is responsible for disposing. Task OpenReadAsync(string path, CancellationToken ct = default); // ── Write ─────────────────────────────────────────────────────── /// Writes data to a file, creating or overwriting it. Task WriteAsync(string path, byte[] data, CancellationToken ct = default); /// Writes a stream to a file, creating or overwriting it. Task WriteAsync(string path, Stream data, CancellationToken ct = default); /// Appends data to an existing file. Task AppendAsync(string path, byte[] data, CancellationToken ct = default); /// Appends text to an existing file. Task AppendTextAsync(string path, string text, System.Text.Encoding encoding, CancellationToken ct = default); // ── File operations ───────────────────────────────────────────── /// Checks whether a file or directory exists. Task ExistsAsync(string path, CancellationToken ct = default); /// Deletes a file. Task DeleteAsync(string path, CancellationToken ct = default); /// Moves (renames) a file from source to destination. Task MoveAsync(string source, string destination, bool overwrite, CancellationToken ct = default); // ── Directory operations ──────────────────────────────────────── /// Creates a directory (and all parent directories if missing). Task CreateDirectoryAsync(string path, CancellationToken ct = default); /// Checks whether a directory exists. Task DirectoryExistsAsync(string path, CancellationToken ct = default); // ── Path helpers ──────────────────────────────────────────────── /// Combines a base path and a relative path using the appropriate separator. string CombinePath(string basePath, string relativePath); /// Returns the parent directory of the given path. string GetParentPath(string path); /// Returns the file name from a path. string GetFileName(string path); /// Returns the file name without extension. string GetFileNameWithoutExtension(string name); /// Returns the extension including the dot (e.g. ".csv"). string GetExtension(string name); /// Returns the relative path from basePath to fullPath. string GetRelativePath(string basePath, string fullPath); /// Checks whether the given path is absolute. bool IsAbsolutePath(string path); } /// /// Extension of for remote file systems (SFTP, FTP). /// Adds connection lifecycle management. /// public interface IRemoteFileOperations : IFileOperations { /// Whether a connection is currently established. bool IsConnected { get; } /// Establishes a connection to the remote server. Task ConnectAsync(CancellationToken ct = default); /// Disconnects from the remote server. Task DisconnectAsync(CancellationToken ct = default); }