| 24 | // FileSystem.stat / lstat return FsStat = { type, size, mtime, mode? }. |
| 25 | |
| 26 | export class WorkspaceFileSystem implements FileSystem { |
| 27 | constructor(private readonly ws: WorkspaceFsLike) {} |
| 28 | |
| 29 | async readFile(path: string): Promise<string> { |
| 30 | const content = await this.ws.readFile(path); |
| 31 | if (content === null) { |
| 32 | throw enoent(path); |
| 33 | } |
| 34 | return content; |
| 35 | } |
| 36 | |
| 37 | async readFileBytes(path: string): Promise<Uint8Array> { |
| 38 | const bytes = await this.ws.readFileBytes(path); |
| 39 | if (bytes === null) { |
| 40 | throw enoent(path); |
| 41 | } |
| 42 | return bytes; |
| 43 | } |
| 44 | |
| 45 | async writeFile(path: string, content: string): Promise<void> { |
| 46 | await this.ws.writeFile(path, content); |
| 47 | } |
| 48 | |
| 49 | async writeFileBytes(path: string, content: Uint8Array): Promise<void> { |
| 50 | await this.ws.writeFileBytes(path, content); |
| 51 | } |
| 52 | |
| 53 | async appendFile(path: string, content: string | Uint8Array): Promise<void> { |
| 54 | if (typeof content === "string") { |
| 55 | await this.ws.appendFile(path, content); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | const existing = await this.ws.readFileBytes(path); |
| 60 | if (existing === null) { |
| 61 | await this.ws.writeFileBytes(path, content); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | const combined = new Uint8Array(existing.byteLength + content.byteLength); |
| 66 | combined.set(existing); |
| 67 | combined.set(content, existing.byteLength); |
| 68 | await this.ws.writeFileBytes(path, combined); |
| 69 | } |
| 70 | |
| 71 | async exists(path: string): Promise<boolean> { |
| 72 | return this.ws.exists(path); |
| 73 | } |
| 74 | |
| 75 | async stat(path: string): Promise<FsStat> { |
| 76 | const s = await this.ws.stat(path); |
| 77 | if (!s) { |
| 78 | throw enoent(path); |
| 79 | } |
| 80 | return fromWorkspaceStat(s); |
| 81 | } |
| 82 | |
| 83 | async lstat(path: string): Promise<FsStat> { |
nothing calls this directly
no outgoing calls
no test coverage detected