(data: Uint8Array)
| 108 | }; |
| 109 | |
| 110 | const 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 | |
| 130 | const assertLikelyUtf8 = (data: Uint8Array): void => { |
| 131 | if (data.length <= FULL_UTF8_VALIDATE_LIMIT) { |
no outgoing calls
no test coverage detected