From 82e7bf9f96bb334f94a483e9c9de0c5c583a7314 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 20 Jan 2023 00:44:46 +0100 Subject: Add detection for gifs when uploading emojis !!UNTESTED!! Signed-off-by: TheArcaneBrony --- src/util/util/Array.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/util') diff --git a/src/util/util/Array.ts b/src/util/util/Array.ts index 1935fa7a..e1008aa2 100644 --- a/src/util/util/Array.ts +++ b/src/util/util/Array.ts @@ -19,3 +19,23 @@ export function containsAll(arr: any[], target: any[]) { return target.every((v) => arr.includes(v)); } + +// Rory - 20/01/2023 - Add utility functions to aid with identification of file types in emojis +export function arrayBufferMatchesArr( + haystack: Uint8Array, + needle: number[], + offset: number, +) { + return arrayBufferMatches(haystack, new Uint8Array(needle), 0); +} + +export function arrayBufferMatches( + haystack: Uint8Array, + needle: Uint8Array, + offset: number, +) { + for (let i = 0; i < needle.length; i++) { + if (haystack[i + offset] !== needle[i]) return false; + } + return true; +} -- cgit 1.5.1