Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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.