mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-15 16:46:04 +00:00
19 lines
568 B
TypeScript
19 lines
568 B
TypeScript
import { MIME_SIGNATURES } from 'stremio/common/CONSTANTS';
|
|
|
|
const SIGNATURES = MIME_SIGNATURES as Record<string, string[]>;
|
|
|
|
const isFileType = (buffer: ArrayBuffer, type: string) => {
|
|
const signatures = SIGNATURES[type];
|
|
|
|
return signatures.some((signature) => {
|
|
const array = new Uint8Array(buffer);
|
|
const signatureBuffer = Buffer.from(signature, 'hex');
|
|
const bufferToCompare = array.subarray(0, signatureBuffer.length);
|
|
|
|
return Buffer.compare(signatureBuffer, bufferToCompare) === 0;
|
|
});
|
|
};
|
|
|
|
export {
|
|
isFileType,
|
|
};
|