Versions 160 to 318
new file, 22 lines
1+import type { GitByteRanges } from "./git-delta-stream.ts"; 3+export class InvalidGitUtf8 extends Error {} 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 }); 9+ const decode = (chunk?: Uint8Array, stream = false) => { 11+ return decoder.decode(chunk, { stream }); 13+ throw new InvalidGitUtf8("Git blob is not UTF-8", { cause: error }); 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); 20+ const tail = decode(); 21+ if (tail) yield tail;