MCPcopy Index your code
hub / github.com/anomalyco/opencode / sniffAttachmentMime

Function sniffAttachmentMime

packages/opencode/src/util/media.ts:15–26  ·  view source on GitHub ↗
(bytes: Uint8Array, fallback: string)

Source from the content-addressed store, hash-verified

13}
14
15export function sniffAttachmentMime(bytes: Uint8Array, fallback: string) {
16 if (startsWith(bytes, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) return "image/png"
17 if (startsWith(bytes, [0xff, 0xd8, 0xff])) return "image/jpeg"
18 if (startsWith(bytes, [0x47, 0x49, 0x46, 0x38])) return "image/gif"
19 if (startsWith(bytes, [0x42, 0x4d])) return "image/bmp"
20 if (startsWith(bytes, [0x25, 0x50, 0x44, 0x46, 0x2d])) return "application/pdf"
21 if (startsWith(bytes, [0x52, 0x49, 0x46, 0x46]) && startsWith(bytes.subarray(8), [0x57, 0x45, 0x42, 0x50])) {
22 return "image/webp"
23 }
24
25 return fallback
26}

Callers 1

read.tsFile · 0.90

Calls 1

startsWithFunction · 0.70

Tested by

no test coverage detected