filetype

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const IMAGE_TMP_FILE_PREFIX = "convert-image" //nolint:staticcheck
View Source
const (
	MAX_READ_FILESIZE = 10 * 1024 * 1024 //nolint:staticcheck
)

Variables

Functions

func ConvertImage2JPG

func ConvertImage2JPG(filename string) (string, error)

ConvertImage2JPG convert image to jpg format (ignore source image filetype). the converted image default store to server temporary directory.

func ConvertImage2PNG

func ConvertImage2PNG(filename string) (string, error)

ConvertImage2PNG convert image to png format (ignore source image filetype), and return the converted image filename.

func Detect

func Detect(filename string) (Filetype, Mime)

Detect detect filetype for binary files and text/plain files. NOTE: the max read file size is 10MB.

func DetectBytes

func DetectBytes(data []byte) (Filetype, Mime)

func GetFiletypeAndMime

func GetFiletypeAndMime(s string) (Filetype, Mime)

GetFiletypeAndMime get the Filetype and Mime by the provided string. It will return FiletypeUnknow, MimeUnknow, if provided string not a available filetype.

Types

type Filetype

type Filetype string
const (
	FiletypeDOC  Filetype = "doc"
	FiletypeXLS  Filetype = "xls"
	FiletypePPT  Filetype = "ppt"
	FiletypeDOCX Filetype = "docx"
	FiletypeXLSX Filetype = "xlsx"
	FiletypePPTX Filetype = "pptx"
	FiletypeODT  Filetype = "odt"
	FiletypeODS  Filetype = "ods"
	FiletypeODP  Filetype = "odp"
	FiletypePDF  Filetype = "pdf"
	FiletypeRTF  Filetype = "rtf"

	FiletypeTXT  Filetype = "txt"
	FiletypeHTML Filetype = "html"
	FiletypeJSON Filetype = "json"
	FiletypeXML  Filetype = "xml"
	FiletypeCSV  Filetype = "csv"
	FiletypePHP  Filetype = "php"
	FiletypeText Filetype = "text"

	FiletypeZIP Filetype = "zip"
	FiletypeTAR Filetype = "tar"
	FiletypeGZ  Filetype = "gz"
	FiletypeBZ2 Filetype = "bz2"
	FiletypeXZ  Filetype = "xz"
	FiletypeLZ  Filetype = "lz"
	FiletypeZST Filetype = "zst"
	FiletypeZ   Filetype = "Z"
	Filetype7Z  Filetype = "7z"
	FiletypeRAR Filetype = "rar"

	FiletypePNG  Filetype = "png"
	FiletypeICO  Filetype = "ico"
	FiletypeJPG  Filetype = "jpg"
	FiletypeGIF  Filetype = "gif"
	FiletypeTIF  Filetype = "tif"
	FiletypeWEBP Filetype = "webp"
	FiletypeSVG  Filetype = "svg"

	FiletypeAVI  Filetype = "avi"
	FiletypeMOV  Filetype = "mov"
	FiletypeMP4  Filetype = "mp4"
	FiletypeWEBM Filetype = "webm"
	FiletypeWMV  Filetype = "wmv"

	FiletypeMP3 Filetype = "mp3"
	FiletypeOGG Filetype = "ogg"
	FiletypeWAV Filetype = "wav"

	FiletypeELF   Filetype = "elf"
	FiletypeEXE   Filetype = "exe"
	FiletypeMACHO Filetype = "macho"
	FiletypeISO   Filetype = "iso"
	FiletypeJAR   Filetype = "jar"

	FiletypeStream Filetype = "binary"
	FiletypeMSI    Filetype = "msi"
	FiletypeOLE    Filetype = "ole"

	FiletypeUnknown Filetype = "unknown"
)

type Mime

type Mime string
const (
	MimeDOC  Mime = "application/msword"
	MimeXLS  Mime = "application/vnd.ms-excel"
	MimePPT  Mime = "application/vnd.ms-powerpoint"
	MimeDOCX Mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
	MimeXLSX Mime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
	MimePPTX Mime = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
	MimeODT  Mime = "application/vnd.oasis.opendocument.text"
	MimeODS  Mime = "application/vnd.oasis.opendocument.spreadsheet"
	MimeODP  Mime = "application/vnd.oasis.opendocument.presentation"
	MimePDF  Mime = "application/pdf"
	MimeRTF  Mime = "application/rtf"

	MimeTXT  Mime = "text/plain; charset=utf-8"
	MimeHTML Mime = "text/html; charset=utf-8"
	MimeJSON Mime = "application/json"
	MimeXML  Mime = "text/xml; charset=utf-8"
	MimeCSV  Mime = "text/csv"
	MimePHP  Mime = "text/x-php"
	MimeTEXT Mime = "text/plain; charset=utf-8"

	MimeZIP Mime = "application/zip"
	MimeTAR Mime = "application/x-tar"
	MimeGZ  Mime = "application/gzip"
	MimeBZ2 Mime = "application/x-bzip2"
	MimeXZ  Mime = "application/x-xz"
	MimeLZ  Mime = "application/x-lzip"
	MimeZST Mime = "application/zstd"
	MimeZ   Mime = "application/x-compress"
	Mime7Z  Mime = "application/x-7z-compressed"
	MimeRAR Mime = "application/vnd.rar"

	MimePNG  Mime = "image/png"
	MimeICO  Mime = "image/vnd.microsoft.icon"
	MimeJPG  Mime = "image/jpeg"
	MimeGIF  Mime = "image/gif"
	MimeTIF  Mime = "image/tiff"
	MimeWEBP Mime = "image/webp"
	MimeSVG  Mime = "image/svg+xml"

	MimeAVI  Mime = "video/x-msvideo"
	MimeMOV  Mime = "video/quicktime"
	MimeMP4  Mime = "video/mp4"
	MimeWEBM Mime = "video/webm"
	MimeWMV  Mime = "video/x-ms-wmv"

	MimeMP3 Mime = "audio/mpeg"
	MimeOGG Mime = "audio/ogg"
	MimeWAV Mime = "audio/x-wav"

	MimeELF   = "application/x-executable"
	MimeEXE   = "application/vnd.microsoft.portable-executable"
	MimeMACHO = "application/x-mach-binary"
	MimeISO   = "application/x-iso9660-image"
	MimeJAR   = "application/jar"

	MimeStream = "application/octet-stream"
	MimeMSI    = "application/x-ms-installer"
	MimeOLE    = "application/x-ole-storage"

	MimeUnknown Mime = "unknown"
)

func MimeByFiletype

func MimeByFiletype(filetype Filetype) Mime

MimeByFiletype get mime by filetype. It will return MimeUnknow if filetype not support or filetype is FiletypeUnknow.

Jump to

Keyboard shortcuts

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