Skip to content

abso-core

Public
Check passed

Versions 160 to 318

Compare

+22 −0 in 1 place
new file, 22 lines
1+import type { GitByteRanges } from "./git-delta-stream.ts";
2+
3+export class InvalidGitUtf8 extends Error {}
4+
5+/** Strict UTF-8 decoding with the same BOM handling as whole-file intake. */
6+export 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+}
MCP
compare on this site's /mcp
CLI
abso diff 160 318 server/src/git-blob-text.ts --json
JSON
/christopher/abso-core/compare/160..318?file=server%2Fsrc%2Fgit-blob-text.ts&format=json