diginext-utils
Version:
README.md
37 lines • 1.22 kB
JavaScript
export default function guessMimeTypeByBuffer(buffer) {
const signature = buffer.toString("hex", 0, 4);
switch (signature) {
case "89504e47":
return "image/png";
case "47494638":
return "image/gif";
case "52494646": {
const webpSignature = buffer.toString("hex", 8, 12);
if (webpSignature === "57454250") {
return "image/webp";
}
break;
}
// MP4, MOV, and other video formats can have multiple signatures
case "00000018":
case "0000001c":
case "00000020":
return "video/mp4";
case "66747970":
return "video/quicktime"; // MOV
case "1a45dfa3": // This is the start of an EBML document (used in WebM, MKV)
return "video/webm";
case "000001ba":
case "000001b3":
return "video/mpeg";
// Add more cases as needed
default:
// Check for JPEG signatures
if (signature.startsWith("ffd8ff")) {
return "image/jpeg";
}
return "unknown";
}
return "unknown";
}
//# sourceMappingURL=guessMimeTypeByBuffer.js.map