MCPcopy
hub / github.com/ampproject/amphtml / batchedRead

Function batchedRead

build-system/common/transform-cache.js:108–124  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

106 * @return {Promise<ReadResult>}
107 */
108function 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
126module.exports = {
127 batchedRead,

Callers 2

jsifyCssAsyncFunction · 0.85
setupFunction · 0.85

Calls 6

md5Function · 0.85
finallyMethod · 0.80
getMethod · 0.45
thenMethod · 0.45
deleteMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected