MCPcopy Index your code
hub / github.com/github/docs / getFileContent

Function getFileContent

lib/get-data.js:266–284  ·  view source on GitHub ↗
(root, relPath, englishRoot)

Source from the content-addressed store, hash-verified

264})
265
266const getFileContent = (root, relPath, englishRoot) => {
267 const filePath = root ? path.join(root, relPath) : relPath
268 if (DEBUG_JIT_DATA_READS) console.log('READ', filePath)
269 try {
270 return fs.readFileSync(filePath, 'utf-8')
271 } catch (err) {
272 // It might fail because that particular data entry doesn't yet
273 // exist in a translation
274 if (err.code === 'ENOENT') {
275 // If looking it up as a file fails, give it one more chance if the
276 // read was for a translation.
277 if (root !== englishRoot) {
278 // We can try again but this time using the English files
279 return getFileContent(englishRoot, relPath, englishRoot)
280 }
281 }
282 throw err
283 }
284}
285
286function memoize(func) {
287 const cache = new Map()

Callers 1

get-data.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected