magicnumber

package
v0.0.0-...-50de45b Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedFile = errors.New("unsupported file")

ErrUnsupportedFile is returned when the detected MIME type of the file isn't in the SupportedMIMEs list or the file is not large enough for us to detect a MIME type on it.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	SupportedMIMEs []string
	MatchedMIME    string
	// contains filtered or unexported fields
}

Checker is an io.WriteCloser that will check to see if the data passed to it is for a file with a MIME type in SupportedMIMEs. If so, MatchedMIME will be set to the MIME type matched and Write and Close will return no error. Otherwise, ErrUnsupportedFile is returned, either from Write as soon as we can tell what MIME type the file is, or from Close if no MIME type has been detected.

func (*Checker) Close

func (m *Checker) Close() error

Close returns ErrUnsupportedFile if no MIME type was detected; this usually indicates a file that is too small for the Checker to detect a MIME type automatically. If the Checker identified a supported MIME type, no error is returned.

func (*Checker) Write

func (m *Checker) Write(b []byte) (int, error)

Write checks the incoming data for magic number bytes that will indicate the MIME type of the data. Once a MIME type is matched, no more data is read into memory, and the function is a no-op. If a MIME type is detected that isn't in SupportedMIMEs, ErrUnsupportedFile is returned.

Jump to

Keyboard shortcuts

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