check

package
v0.3.30 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DetCgyMap = map[string]FileCategory{
	"image/x-icon":     FileCategoryImage,
	"image/bmp":        FileCategoryImage,
	"image/gif":        FileCategoryImage,
	"image/webp":       FileCategoryImage,
	"image/png":        FileCategoryImage,
	"image/jpeg":       FileCategoryImage,
	"video/webm":       FileCategoryVideo,
	"video/mp4":        FileCategoryVideo,
	"video/avi":        FileCategoryVideo,
	"application/ogg":  FileCategoryVideo,
	"audio/mpeg":       FileCategoryAudio,
	"audio/aiff":       FileCategoryAudio,
	"audio/midi":       FileCategoryAudio,
	"audio/wave":       FileCategoryAudio,
	"application/wasm": FileCategoryWasm,
}

DetCgyMap is a map of file extensions to their corresponding FileCategory.

ExtCgyMap is a map of file extensions to their corresponding FileCategory.

Functions

func FileTypeByDetectContentType

func FileTypeByDetectContentType(bs []byte) string

FileTypeByDetectContentType detects the content type of the given byte slice.

func SaveUploadedFileWithCheck added in v0.3.16

func SaveUploadedFileWithCheck(file *multipart.FileHeader, dst string, allowCategorys ...FileCategory) error

SaveUploadedFileWithCheck saves an uploaded file while performing checks.

Types

type FileCategory

type FileCategory int32

FileCategory represents the category of a file.

const (
	FileCategoryNil FileCategory = iota
	FileCategoryImage
	FileCategoryVideo
	FileCategoryAudio
	FileCategoryWasm
)

Constants representing the different file categories.

func GetFileCategoryByDet

func GetFileCategoryByDet(det string) FileCategory

GetFileCategoryByDet returns the FileCategory for a given detection string.

func GetFileCategoryByExt

func GetFileCategoryByExt(ext string) FileCategory

GetFileCategoryByExt returns the FileCategory for a given file extension.

func (FileCategory) Ok

func (t FileCategory) Ok(filepath string) bool

The Ok function determines whether the given file path belongs to the specified file category. Parameters:

  • filepath: File path

Return value:

  • bool: Returns true if the file path is of the specified file category; otherwise, returns false.

func (FileCategory) OkBs added in v0.3.15

func (t FileCategory) OkBs(r []byte) bool

OkBs checks if the given byte slice belongs to the specified file category. It first detects the content type of the byte slice using FileTypeByDetectContentType. Then it checks if the detected file category matches the specified file category. Returns true if the byte slice belongs to the specified file category, otherwise false.

func (FileCategory) OkRead

func (t FileCategory) OkRead(r io.Reader) bool

The OkRead function determines whether the content from the provided io.Reader belongs to the specified file category. Parameters:

  • r: io.Reader

Return value:

  • bool: Returns true if the content from the io.Reader is of the specified file category; otherwise, returns false.

type FileTypeFunc

type FileTypeFunc func(bs []byte) string

FileTypeFunc is a function type that takes a byte slice and returns a string.

func (FileTypeFunc) FrmFile

func (f FileTypeFunc) FrmFile(filepath string) (string, error)

FrmFile reads from the given file and returns the file type using the FileTypeFunc.

func (FileTypeFunc) FrmReader

func (f FileTypeFunc) FrmReader(r io.Reader) (string, error)

FrmReader reads from the given reader and returns the file type using the FileTypeFunc.

Jump to

Keyboard shortcuts

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