MCPcopy Index your code
hub / github.com/docker/docker-agent / detectMimeTypeFromFile

Function detectMimeTypeFromFile

pkg/chat/chat.go:203–216  ·  view source on GitHub ↗

detectMimeTypeFromFile reads the first 512 bytes of a file and uses content-based detection (magic bytes) to determine the MIME type.

(filePath string)

Source from the content-addressed store, hash-verified

201// detectMimeTypeFromFile reads the first 512 bytes of a file and uses
202// content-based detection (magic bytes) to determine the MIME type.
203func detectMimeTypeFromFile(filePath string) string {
204 f, err := os.Open(filePath)
205 if err != nil {
206 return "application/octet-stream"
207 }
208 defer f.Close()
209
210 buf := make([]byte, 512)
211 n, _ := f.Read(buf)
212 if n == 0 {
213 return "application/octet-stream"
214 }
215 return DetectMimeTypeByContent(buf[:n])
216}
217
218// IsImageMimeType returns true if the MIME type is a supported image type.
219func IsImageMimeType(mimeType string) bool {

Callers 1

DetectMimeTypeFunction · 0.85

Calls 4

DetectMimeTypeByContentFunction · 0.85
OpenMethod · 0.65
CloseMethod · 0.65
ReadMethod · 0.65

Tested by

no test coverage detected