MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / assertLikelyUtf8

Function assertLikelyUtf8

src/pkg/utils/encoding.ts:130–140  ·  view source on GitHub ↗
(data: Uint8Array)

Source from the content-addressed store, hash-verified

128};
129
130const assertLikelyUtf8 = (data: Uint8Array): void => {
131 if (data.length <= FULL_UTF8_VALIDATE_LIMIT) {
132 new TextDecoder("utf-8", { fatal: true }).decode(data);
133 return;
134 }
135
136 const decoder = new TextDecoder("utf-8", { fatal: true });
137 for (const [start, end] of createSampleRanges(data)) {
138 decoder.decode(data.subarray(start, end));
139 }
140};
141
142const decodeMostlyUtf8 = (data: Uint8Array): string | null => {
143 const decoded = new TextDecoder("utf-8").decode(data);

Callers 1

readRawContentFunction · 0.85

Calls 1

createSampleRangesFunction · 0.85

Tested by

no test coverage detected