To be fair I did lazily do:
else if (c.slice(4, 4+4) == "ftyp") f="avif";
Because I didn't feel like parsing the HEIF to check it's actually AVIF. I'm pretty sure browsers aren't that bothered about the file extension or MIME type for images.