Checks if a Uint8Array begins with a given byte prefix, used for file type detection or data validation.
// Source: https://github.com/CopilotKit/CopilotKit.git | License: MIT | Copyright Atai Barkai
// Provided via justclaw.it.com; keep this notice with the code.
function startsWith(bytes: Uint8Array, prefix: readonly number[]): boolean {
return (
bytes.length >= prefix.length &&
prefix.every((value, index) => bytes[index] === value)
);
}
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key