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

Function catFileWith

packages/computer/src/git/plumbing.ts:118–162  ·  view source on GitHub ↗
(opts: CatFileWithDeps)

Source from the content-addressed store, hash-verified

116}
117
118export async function catFileWith(opts: CatFileWithDeps): Promise<CatFileResult> {
119 const dir = opts.dir ?? "/";
120 try {
121 // readBlob is the right tool when we already know the oid
122 // resolves to a blob; for tree / commit oids it errors out.
123 // We try readBlob first (fast path); fall back to readObject
124 // when the caller doesn't know the type up front.
125 if (opts.filepath !== undefined) {
126 const { oid, blob } = await opts.git.readBlob({
127 fs: opts.fs,
128 dir,
129 oid: opts.oid,
130 filepath: opts.filepath,
131 cache: opts.cache,
132 });
133 return { oid, bytes: blob };
134 }
135 try {
136 const { oid, blob } = await opts.git.readBlob({
137 fs: opts.fs,
138 dir,
139 oid: opts.oid,
140 cache: opts.cache,
141 });
142 return { oid, bytes: blob };
143 } catch {
144 // Not a blob; fall through to readObject's content form.
145 }
146 const obj = await opts.git.readObject({
147 fs: opts.fs,
148 dir,
149 oid: opts.oid,
150 format: "content",
151 cache: opts.cache,
152 });
153 const bytes =
154 obj.object instanceof Uint8Array ? obj.object : new TextEncoder().encode(String(obj.object));
155 return { oid: obj.oid, bytes };
156 } catch (cause) {
157 if (isNotARepositoryCause(cause)) throw new NotARepositoryError(dir, { cause });
158 throw new GitError("ECATFILEFAIL", `git cat-file failed: ${errorMessage(cause)}`, {
159 cause,
160 });
161 }
162}
163
164// ---------------------------------------------------------------
165// updateRef

Callers 2

catFileFunction · 0.85
plumbing.test.tsFile · 0.85

Calls 4

isNotARepositoryCauseFunction · 0.85
readObjectMethod · 0.80
errorMessageFunction · 0.70
readBlobMethod · 0.65

Tested by

no test coverage detected