1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-17 08:02:40 +08:00
This commit is contained in:
2022-06-22 11:03:54 +08:00
parent ed9a684933
commit 2fd5c8e662

28
fs/mime.go Normal file
View File

@ -0,0 +1,28 @@
package fs
import (
"io"
"net/http"
"os"
)
func GetMimeByFileName(filename string) string {
f, err := os.Open(filename)
if err != nil {
}
defer f.Close()
return GetMimeByStream(f)
}
func GetMimeByStream(fp io.Reader) string {
buf := make([]byte, 32)
fp.Read(buf)
return http.DetectContentType(buf)
}
func GetMimeByBytes(b []byte) string {
return http.DetectContentType(b)
}