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

Function createLegacyDetectionSample

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

Source from the content-addressed store, hash-verified

108};
109
110const createLegacyDetectionSample = (data: Uint8Array): Uint8Array => {
111 const n = data.length;
112 if (n <= LEGACY_SAMPLE_LIMIT) return data;
113
114 let firstHighByteIndex = -1;
115 for (let i = 0; i < n; i++) {
116 if (data[i] >= 0x80) {
117 firstHighByteIndex = i;
118 break;
119 }
120 }
121
122 if (firstHighByteIndex < 0) {
123 return data.subarray(0, LEGACY_SAMPLE_LIMIT);
124 }
125
126 const sampleStart = Math.max(0, Math.min(firstHighByteIndex - 8 * 1024, n - LEGACY_SAMPLE_LIMIT));
127 return data.subarray(sampleStart, sampleStart + LEGACY_SAMPLE_LIMIT);
128};
129
130const assertLikelyUtf8 = (data: Uint8Array): void => {
131 if (data.length <= FULL_UTF8_VALIDATE_LIMIT) {

Callers 1

legacyDetectEncodingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected