MCPcopy
hub / github.com/perkeep/perkeep / MIMETypeFromReader

Function MIMETypeFromReader

internal/magic/magic.go:199–207  ·  view source on GitHub ↗

MIMETypeFromReader takes a reader, sniffs the beginning of it, and returns the mime (if sniffed, else "") and a new reader that's the concatenation of the bytes sniffed and the remaining reader.

(r io.Reader)

Source from the content-addressed store, hash-verified

197// that's the concatenation of the bytes sniffed and the remaining
198// reader.
199func MIMETypeFromReader(r io.Reader) (mime string, reader io.Reader) {
200 var buf bytes.Buffer
201 _, err := io.Copy(&buf, io.LimitReader(r, 1024))
202 mime = MIMEType(buf.Bytes())
203 if err != nil {
204 return mime, io.MultiReader(&buf, errReader{err})
205 }
206 return mime, io.MultiReader(&buf, r)
207}
208
209// MIMETypeFromReaderAt takes a ReaderAt, sniffs the beginning of it,
210// and returns the MIME type if sniffed, else the empty string.

Callers 4

populateFileMethod · 0.92
TestMakeThumbnailFunction · 0.92
showMIMEFunction · 0.92
TestMIMETypeFromReaderFunction · 0.85

Calls 1

MIMETypeFunction · 0.85

Tested by 2

TestMakeThumbnailFunction · 0.74
TestMIMETypeFromReaderFunction · 0.68