MCPcopy Create free account
hub / github.com/AandStep/ResultV / imageContentTypeFromBytes

Function imageContentTypeFromBytes

app.go:1700–1729  ·  view source on GitHub ↗
(buf []byte, headerCT string)

Source from the content-addressed store, hash-verified

1698}
1699
1700func imageContentTypeFromBytes(buf []byte, headerCT string) string {
1701 ct := strings.ToLower(strings.TrimSpace(strings.Split(headerCT, ";")[0]))
1702 if strings.HasPrefix(ct, "image/") {
1703 return ct
1704 }
1705 if ct == "application/vnd.microsoft.icon" || ct == "image/vnd.microsoft.icon" {
1706 return "image/x-icon"
1707 }
1708 if len(buf) >= 8 && buf[0] == 0x89 && buf[1] == 0x50 && buf[2] == 0x4e && buf[3] == 0x47 {
1709 return "image/png"
1710 }
1711 if len(buf) >= 4 && buf[0] == 0 && buf[1] == 0 && buf[2] == 1 && buf[3] == 0 {
1712 return "image/x-icon"
1713 }
1714 if len(buf) >= 2 && buf[0] == 0xff && buf[1] == 0xd8 {
1715 return "image/jpeg"
1716 }
1717 if len(buf) >= 6 {
1718 s6 := string(buf[0:6])
1719 if s6 == "GIF87a" || s6 == "GIF89a" {
1720 return "image/gif"
1721 }
1722 }
1723 if ct == "application/octet-stream" || ct == "binary/octet-stream" || ct == "" {
1724 if g := http.DetectContentType(buf); strings.HasPrefix(strings.ToLower(g), "image/") {
1725 return strings.ToLower(g)
1726 }
1727 }
1728 return ""
1729}
1730
1731// isPrivateOrLoopback reports whether the given IP belongs to a range that
1732// the icon-fetch must not reach. We block loopback, link-local, multicast,

Callers 1

inlineSmallImageFromURLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected