(path: string, flags: string = "r", _mode?: number)
| 139 | } |
| 140 | |
| 141 | openSync(path: string, flags: string = "r", _mode?: number): number { |
| 142 | const { read, write, truncate, append, create, exclusive } = parseFlags(flags); |
| 143 | const existing = resolveInode(this.db, path); |
| 144 | |
| 145 | if (existing === null) { |
| 146 | if (!create) { |
| 147 | throw createWorkspaceError("ENOENT", `no such file: ${path}`, path); |
| 148 | } |
| 149 | writeFileSyncImpl(this.db, path, new Uint8Array(), {}, this.now); |
| 150 | } else { |
| 151 | if (existing.type !== "file") { |
| 152 | throw createWorkspaceError("EISDIR", `path is a directory: ${path}`, path); |
| 153 | } |
| 154 | if (exclusive) { |
| 155 | throw createWorkspaceError("EEXIST", `path exists: ${path}`, path); |
| 156 | } |
| 157 | if (truncate) { |
| 158 | writeFileSyncImpl(this.db, path, new Uint8Array(), {}, this.now); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | const stat = statImpl(this.db, path); |
| 163 | const fd = this.#nextFd++; |
| 164 | this.#fds.set(fd, { |
| 165 | path, |
| 166 | position: append ? stat.size : 0, |
| 167 | readable: read, |
| 168 | writable: write, |
| 169 | append, |
| 170 | }); |
| 171 | return fd; |
| 172 | } |
| 173 | |
| 174 | stat(path: string, options?: { bigint?: boolean }): Promise<VirtualStatsLike> { |
| 175 | return Promise.resolve(this.statSync(path, options)); |
no test coverage detected