func (vbag *VirtualBag) setMimeType(reader io.Reader, gf *GenericFile) { // on err, defaults to application/binary buf := make([]byte, 128) _, err := reader.Read(buf) if err != nil { vbag.summary.AddError(err.Error()) } gf.FileFormat, err = platform.GuessMimeTypeByBuffer(buf) if err != nil { vbag.summary.AddError(err.Error()) } }
func TestGuessMimeTypeByBuffer(t *testing.T) { pathToTempFile := setupMimeTest(t) defer teardownMimeTest(pathToTempFile) file, err := os.Open(pathToTempFile) require.Nil(t, err) defer file.Close() buf := make([]byte, 256) _, _ = file.Read(buf) mimetype, err := platform.GuessMimeTypeByBuffer(buf) require.Nil(t, err) if !platform.IsPartnerBuild { assert.Equal(t, "text/plain", mimetype) } }