(bytes: Uint8Array)
| 396 | }; |
| 397 | |
| 398 | const sniffMimeType = (bytes: Uint8Array): string | null => { |
| 399 | if (startsWithBytes(bytes, [0xff, 0xd8, 0xff])) return "image/jpeg"; |
| 400 | if (startsWithBytes(bytes, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) { |
| 401 | return "image/png"; |
| 402 | } |
| 403 | if ( |
| 404 | startsWithBytes(bytes, [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]) || |
| 405 | startsWithBytes(bytes, [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]) |
| 406 | ) { |
| 407 | return "image/gif"; |
| 408 | } |
| 409 | if ( |
| 410 | startsWithBytes(bytes, [0x52, 0x49, 0x46, 0x46]) && |
| 411 | bytes[8] === 0x57 && |
| 412 | bytes[9] === 0x45 && |
| 413 | bytes[10] === 0x42 && |
| 414 | bytes[11] === 0x50 |
| 415 | ) { |
| 416 | return "image/webp"; |
| 417 | } |
| 418 | if (startsWithBytes(bytes, [0x25, 0x50, 0x44, 0x46, 0x2d])) return "application/pdf"; |
| 419 | if ( |
| 420 | startsWithBytes(bytes, [0x50, 0x4b, 0x03, 0x04]) || |
| 421 | startsWithBytes(bytes, [0x50, 0x4b, 0x05, 0x06]) || |
| 422 | startsWithBytes(bytes, [0x50, 0x4b, 0x07, 0x08]) |
| 423 | ) { |
| 424 | return "application/zip"; |
| 425 | } |
| 426 | if (isLikelyUtf8Text(bytes)) return "text/plain"; |
| 427 | return null; |
| 428 | }; |
| 429 | |
| 430 | const bytesFromBase64Prefix = (base64: string): Uint8Array => { |
| 431 | const prefix = base64.slice(0, Math.min(base64.length, 64)); |
no test coverage detected