mimetype

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const BytesThreshold = 1024

BytesThreshold is the size of the validation buffer.

Variables

This section is empty.

Functions

func ValidateMimeTypePattern

func ValidateMimeTypePattern(pattern string) error

ValidateMimeTypePattern validates that the checks extracted from pattern can be used as glob patterns against mime types.

Types

type Check

type Check struct {
	// contains filtered or unexported fields
}

Check holds info on a specific test check is a string/mimetype to be matched negate indicates if the check should be handled as a blacklist or a whitelist.

func (Check) IsValid

func (c Check) IsValid(mime string) bool

IsValid validates the given mime string against the current check.

type ErrMimeTypeMismatch

type ErrMimeTypeMismatch struct {
	// contains filtered or unexported fields
}

ErrMimeTypeMismatch is a custom error exposing info on the given failed check.

func (ErrMimeTypeMismatch) Error

func (e ErrMimeTypeMismatch) Error() string

Error returns the error string for the current ErrMimeTypeMismatch.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator checks its buffer's mime type against the provided checks. It holds a reference to a mime type decoder.

func New

func New() (*Validator, error)

New constructs a new validator.

func (*Validator) CheckBuffer

func (v *Validator) CheckBuffer(p []byte) error

CheckBuffer performs mime types checks against the provided byte slice.

func (*Validator) Close

func (v *Validator) Close()

Close closes the internal mime-type decoder.

func (*Validator) Read

func (v *Validator) Read(r io.Reader) error

Read takes an io.Reader as an argument, tries to read MimeTypeValidationThreshold of input bytes, or fewer if the request is shorter. It then performs mime type checks against its buffer. Any r.Read() errors are returned verbatim.

func (*Validator) Reset

func (v *Validator) Reset(expectedMimePattern string)

Reset resets the current validatorby reinitializing all checks based on the given pattern.

Jump to

Keyboard shortcuts

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