| 116 | * - Custom implementations (e.g., remote storage, browser IndexedDB) |
| 117 | */ |
| 118 | export interface IFileSystem { |
| 119 | // Note: Sync method are not supported and must not be added. |
| 120 | /** |
| 121 | * Read the contents of a file as decoded text. Default encoding is utf8; |
| 122 | * pass an explicit text encoding (`"ascii"`, etc.) to override. |
| 123 | * |
| 124 | * For raw bytes (encoding `"binary"` / `"latin1"`), use {@link readFileBytes} |
| 125 | * — the opaque return type forces callers to decide whether to forward |
| 126 | * bytes unchanged or decode as text. |
| 127 | * |
| 128 | * @throws Error if file doesn't exist or is a directory |
| 129 | */ |
| 130 | readFile( |
| 131 | path: string, |
| 132 | options?: ReadFileOptions | BufferEncoding, |
| 133 | ): Promise<string>; |
| 134 | |
| 135 | /** |
| 136 | * Read the raw bytes of a file as a {@link ByteString} (latin1-shaped: each |
| 137 | * char = one byte). Use when the bytes will be piped onward unchanged or |
| 138 | * explicitly decoded with `decodeBytesToUtf8` — never call string methods |
| 139 | * on the result, that's the bug class this type prevents. |
| 140 | * |
| 141 | * Optional for backwards compatibility with external `IFileSystem` |
| 142 | * implementations written before this method existed; built-in |
| 143 | * filesystems all implement it. Internal callers must route through the |
| 144 | * `readBytesFrom(fs, path)` helper, which falls back to `readFileBuffer` |
| 145 | * when this method is missing. |
| 146 | * |
| 147 | * @throws Error if file doesn't exist or is a directory |
| 148 | */ |
| 149 | readFileBytes?(path: string): Promise<ByteString>; |
| 150 | |
| 151 | /** |
| 152 | * Read the contents of a file as a Uint8Array (binary) |
| 153 | * @throws Error if file doesn't exist or is a directory |
| 154 | */ |
| 155 | readFileBuffer(path: string): Promise<Uint8Array>; |
| 156 | |
| 157 | /** |
| 158 | * Write content to a file, creating it if it doesn't exist |
| 159 | */ |
| 160 | writeFile( |
| 161 | path: string, |
| 162 | content: FileContent, |
| 163 | options?: WriteFileOptions | BufferEncoding, |
| 164 | ): Promise<void>; |
| 165 | |
| 166 | /** |
| 167 | * Append content to a file, creating it if it doesn't exist |
| 168 | */ |
| 169 | appendFile( |
| 170 | path: string, |
| 171 | content: FileContent, |
| 172 | options?: WriteFileOptions | BufferEncoding, |
| 173 | ): Promise<void>; |
| 174 | |
| 175 | /** |
no outgoing calls
no test coverage detected
searching dependent graphs…