- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/src/git-blob-text.ts?format=json
22 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 178, 1 version changed it
1import type { GitByteRanges } from "./git-delta-stream.ts";
3export class InvalidGitUtf8 extends Error {}
5/** Strict UTF-8 decoding with the same BOM handling as whole-file intake. */
6export function* gitBlobText(bytes: GitByteRanges): IterableIterator<string> {
7 const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: false });
8 const size = 16384;
9 const decode = (chunk?: Uint8Array, stream = false) => {
10 try {
11 return decoder.decode(chunk, { stream });
12 } catch (error) {
13 throw new InvalidGitUtf8("Git blob is not UTF-8", { cause: error });
14 }
15 };
16 for (let at = 0; at < bytes.byteLength; at += size) {
17 const text = decode(bytes.read(at, Math.min(size, bytes.byteLength - at)), true);
18 for (let offset = 0; offset < text.length; offset += size) yield text.slice(offset, offset + size);
19 }
20 const tail = decode();
21 if (tail) yield tail;
22}