MCPcopy Create free account
hub / github.com/cloudflare/computer / readBlobAsText

Function readBlobAsText

packages/computer/src/git/diff.ts:287–304  ·  view source on GitHub ↗
(
  git: IsomorphicGitDiffClient,
  fs: object,
  dir: string,
  oid: string,
  filepath: string,
  cache: object | undefined,
)

Source from the content-addressed store, hash-verified

285}
286
287async function readBlobAsText(
288 git: IsomorphicGitDiffClient,
289 fs: object,
290 dir: string,
291 oid: string,
292 filepath: string,
293 cache: object | undefined,
294): Promise<string> {
295 try {
296 const { blob } = await git.readBlob({ fs, dir, oid, filepath, cache });
297 // Best-effort UTF-8 decode. A real diff tool would skip
298 // binaries entirely; for the general case here a noisy diff
299 // beats a thrown error.
300 return new TextDecoder("utf-8", { fatal: false, ignoreBOM: false }).decode(blob);
301 } catch {
302 return "";
303 }
304}
305
306async function readWorkdirAsText(
307 readFile: ReadFileFn,

Callers 2

collectDiffEntriesFunction · 0.85
collectRefToRefFunction · 0.85

Calls 1

readBlobMethod · 0.65

Tested by

no test coverage detected