| 222 | // one cut short or changed since it was written reads as missing, and is |
| 223 | // written again |
| 224 | private read(name: string): unknown { |
| 225 | let text: string |
| 226 | try { |
| 227 | text = readFileSync(join(this.dir, `${name}.json`), "utf8") |
| 228 | } catch { |
| 229 | return |
| 230 | } |
| 231 | const start = text.indexOf("\n") + 1 |
| 232 | const body = text.slice(start) |
| 233 | if (start && text.slice(0, start - 1) === hashOf(body)) |
| 234 | return JSON.parse(body) |
| 235 | } |
| 236 | |
| 237 | // with its hash, and renamed into place once written, so a concurrent build |
| 238 | // reads all of it or none, and the last of two writing it wins. Its temp |