mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-17 16:12:42 +08:00
mime
This commit is contained in:
28
fs/mime.go
Normal file
28
fs/mime.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user