{"draft":null,"from":116,"to":318,"files":[{"path":"server/src/git-blob-text.ts","added":22,"removed":0,"diff":"--- /dev/null\n+++ b/server/src/git-blob-text.ts\n@@ -0,0 +1,22 @@\n+import type { GitByteRanges } from \"./git-delta-stream.ts\";\n+\n+export class InvalidGitUtf8 extends Error {}\n+\n+/** Strict UTF-8 decoding with the same BOM handling as whole-file intake. */\n+export function* gitBlobText(bytes: GitByteRanges): IterableIterator<string> {\n+\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: false });\n+\tconst size = 16384;\n+\tconst decode = (chunk?: Uint8Array, stream = false) => {\n+\t\ttry {\n+\t\t\treturn decoder.decode(chunk, { stream });\n+\t\t} catch (error) {\n+\t\t\tthrow new InvalidGitUtf8(\"Git blob is not UTF-8\", { cause: error });\n+\t\t}\n+\t};\n+\tfor (let at = 0; at < bytes.byteLength; at += size) {\n+\t\tconst text = decode(bytes.read(at, Math.min(size, bytes.byteLength - at)), true);\n+\t\tfor (let offset = 0; offset < text.length; offset += size) yield text.slice(offset, offset + size);\n+\t}\n+\tconst tail = decode();\n+\tif (tail) yield tail;\n+}"}],"unmatched":[]}