| 55 | } |
| 56 | |
| 57 | function memoryStore(options: { |
| 58 | content?: string; |
| 59 | mode?: number; |
| 60 | size?: number; |
| 61 | statError?: Error; |
| 62 | readError?: Error; |
| 63 | writeError?: Error; |
| 64 | onWrite?: (path: string, content: Uint8Array, opts?: { mode?: number }) => void; |
| 65 | }): FileStore { |
| 66 | const content = options.content ?? ""; |
| 67 | return { |
| 68 | async stat() { |
| 69 | if (options.statError) throw options.statError; |
| 70 | return { |
| 71 | size: options.size ?? bytes(content).byteLength, |
| 72 | mtime: 1, |
| 73 | mode: options.mode, |
| 74 | }; |
| 75 | }, |
| 76 | async readAll() { |
| 77 | if (options.readError) throw options.readError; |
| 78 | return bytes(content); |
| 79 | }, |
| 80 | async *readChunks() { |
| 81 | if (options.readError) throw options.readError; |
| 82 | yield bytes(content); |
| 83 | }, |
| 84 | async write(path, nextContent, opts) { |
| 85 | if (options.writeError) throw options.writeError; |
| 86 | options.onWrite?.(path, nextContent, opts); |
| 87 | }, |
| 88 | }; |
| 89 | } |
| 90 | |
| 91 | describe("WorkspaceFileStore", () => { |
| 92 | it("slices byte ranges while reading chunks from Workspace.fs", async () => { |