MCPcopy Create free account
hub / github.com/cloudbase/garm / DetectFileType

Function DetectFileType

util/util.go:166–183  ·  view source on GitHub ↗

DetectFileType detects the MIME type from file content

(data []byte)

Source from the content-addressed store, hash-verified

164
165// DetectFileType detects the MIME type from file content
166func DetectFileType(data []byte) string {
167 // First, try http.DetectContentType (good for text files)
168 httpType := http.DetectContentType(data)
169
170 // If http detected text, use that
171 if httpType != "application/octet-stream" {
172 return httpType
173 }
174
175 // For binary files, use filetype library for specific format detection
176 kind, err := filetype.Match(data)
177 if err == nil && kind != filetype.Unknown {
178 return kind.MIME.Value
179 }
180
181 // Default to application/octet-stream for unknown types
182 return "application/octet-stream"
183}
184
185func GetTmpFileHandle(baseDir string) (*os.File, error) {
186 tmpDir, err := getTempDir(baseDir)

Callers 1

CreateFileObjectMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected