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

Function detectBOM

src/pkg/utils/encoding.ts:225–237  ·  view source on GitHub ↗
(u8: Uint8Array)

Source from the content-addressed store, hash-verified

223};
224
225const detectBOM = (u8: Uint8Array): string | null => {
226 // UTF-8 BOM
227 if (u8[0] === 0xef && u8[1] === 0xbb && u8[2] === 0xbf) return "utf-8";
228
229 // UTF-16
230 if (u8[0] === 0xff && u8[1] === 0xfe) return u8[2] === 0 && u8[3] === 0 ? "utf-32le" : "utf-16le";
231 if (u8[0] === 0xfe && u8[1] === 0xff) return "utf-16be";
232
233 // UTF-32BE
234 if (u8[0] === 0 && u8[1] === 0 && u8[2] === 0xfe && u8[3] === 0xff) return "utf-32be";
235
236 return null;
237};
238
239function guessByNullPattern(u8: Uint8Array, size = u8.length): string | null {
240 if (size < 64) return null;

Callers 1

readRawContentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected