mimeTypeKit

package
v2.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detect

func Detect(in []byte) *mimetype.MIME

Detect

mimetype库: 基于magic数的用于媒体类型和文件扩展名检测的快速的 Go 库,支持 170+ 格式.

e.g.

mime := mimeTypeKit.Detect(nil)
fmt.Println(mime.String()) // "text/plain"

func DetectContentType

func DetectContentType(data []byte) string

DetectContentType 获取 ContentType(即MimeType).

@return 保底 "application/octet-stream"

e.g. ([]byte(nil)) => "text/plain; charset=utf-8" ([]byte{}) => "text/plain; charset=utf-8"

func DetectFile

func DetectFile(path string) (*mimetype.MIME, error)

DetectFile

PS: 默认limit为: 3KB(3072).

TODO: https://github.com/gabriel-vasile/mimetype

mimetype.SetLimit(1024*1024) // Set limit to 1MB.
// or
mimetype.SetLimit(0) // No limit, whole file content used.
mimetype.DetectFile("file.doc")

e.g.

mime, _ := mimeTypeKit.DetectFile("/Users/richelieu/Desktop/未命名.wps")
fmt.Println(mime.String()) // application/x-ole-storage

mime, _ = mimeTypeKit.DetectFile("/Users/richelieu/Desktop/download.pdf")
fmt.Println(mime.String()) // application/pdf

func DetectReader

func DetectReader(r io.Reader) (*mimetype.MIME, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL