* Returns the string contents and hash of the file at the specified path. If * multiple reads are requested for the same file before the first read has * completed, the result will be reused. * * @param {string} path * @return {Promise }
(path)
| 106 | * @return {Promise<ReadResult>} |
| 107 | */ |
| 108 | function batchedRead(path) { |
| 109 | let read = readCache.get(path); |
| 110 | if (!read) { |
| 111 | read = fs |
| 112 | .readFile(path) |
| 113 | .then((contents) => ({ |
| 114 | contents, |
| 115 | hash: md5(contents), |
| 116 | })) |
| 117 | .finally(() => { |
| 118 | readCache.delete(path); |
| 119 | }); |
| 120 | readCache.set(path, read); |
| 121 | } |
| 122 | |
| 123 | return read; |
| 124 | } |
| 125 | |
| 126 | module.exports = { |
| 127 | batchedRead, |