func MatchMime(_ string, data []byte) string {
	mt, _ := filetype.Match(data)
	return mt.MIME.Type + "/" + mt.MIME.Subtype
}
MatchMime checks mime from the first 1024 bytes
package camutil
import (
	"bytes"
	"io"
	"github.com/h2non/filetype"
	"github.com/hashicorp/golang-lru"
	"perkeep.org/pkg/sorted"
	"perkeep.org/pkg/sorted/kvfile"
)
var DefaultMaxMemMimeCacheSize = 1024
func MIMETypeFromReader(r io.Reader) (mime string, reader io.Reader) {
	if r == nil {
		return "", nil
	}
	var buf bytes.Buffer
	_, err := io.Copy(&buf, io.LimitReader(r, 1024))
	mt, _ := filetype.Match(buf.Bytes())
	mime = mt.MIME.Type + "/" + mt.MIME.Subtype
	if err != nil {
		return mime, io.MultiReader(bytes.NewReader(buf.Bytes()), errReader{err})
	}
	return mime, io.MultiReader(bytes.NewReader(buf.Bytes()), r)
}
type MimeCache struct {
	mem *lru.TwoQueueCache
	db  sorted.KeyValue
}
func NewMimeCache(filename string, maxMemCacheSize int) *MimeCache {
	mc := new(MimeCache)
	if maxMemCacheSize <= 0 {
		maxMemCacheSize = DefaultMaxMemMimeCacheSize
	}
	var err error
	if mc.mem, err = lru.New2Q(maxMemCacheSize); err != nil {
		panic(err)
	}
	if mc.db, err = kvfile.NewStorage(filename); err != nil {
		Log("msg", "cannot open/create db", "file", filename, "error", err)
		mc.db = nil
	}
	return mc
}
func (mc *MimeCache) Close() error {
	if mc.db != nil {
		return mc.db.Close()
	}
	return nil
}
func (mc *MimeCache) Get(key string) string {
	if mti, ok := mc.mem.Get(key); ok {
		return mti.(string)
	}
	if mc.db != nil {
		if mimetype, err := mc.db.Get(key); err == nil {
			return mimetype
		}
	}
	return ""
}
func (mc *MimeCache) Set(key, mime string) {
	if mime == "" {
		return
	}
	mc.mem.Add(key, mime)
	if mc.db != nil {
		if err := mc.db.Set(key, mime); err != nil {
			Log("msg", "error setting", "key", key, "mime", mime, "db", mc.db, "error", err)
		}
	}
}