func (d *Decoder) TypeByBuffer(blob []byte) (string, error) {
	bytes := unsafe.Pointer(&blob[0])
	out := C.magic_buffer(d.db, bytes, C.size_t(len(blob)))
	if out == nil {
		return "", errors.New(C.GoString(C.magic_error(d.db)))
	}
	return C.GoString(out), nil
}
TypeByBuffer looks up for a blob's mimetype by its contents.
It uses a magic number database which is described in magic(5).
package magicmime
import "C"
import (
	"errors"
	"sync"
	"unsafe"
)
type Decoder struct {
	db C.magic_t
}
var (
	decMu sync.Mutex
	dec   *Decoder
)
type Flag int
const (
	MAGIC_NONE Flag = C.MAGIC_NONE
	MAGIC_DEBUG Flag = C.MAGIC_DEBUG
	MAGIC_SYMLINK Flag = C.MAGIC_SYMLINK
	MAGIC_COMPRESS Flag = C.MAGIC_COMPRESS
	MAGIC_DEVICES Flag = C.MAGIC_DEVICES
	MAGIC_MIME_TYPE Flag = C.MAGIC_MIME_TYPE
	MAGIC_MIME_ENCODING Flag = C.MAGIC_MIME_ENCODING
	MAGIC_MIME Flag = C.MAGIC_MIME
	MAGIC_CONTINUE Flag = C.MAGIC_CONTINUE
	MAGIC_CHECK Flag = C.MAGIC_CHECK
	MAGIC_PRESERVE_ATIME Flag = C.MAGIC_PRESERVE_ATIME
	MAGIC_RAW Flag = C.MAGIC_RAW
	MAGIC_ERROR Flag = C.MAGIC_ERROR
	MAGIC_APPLE Flag = C.MAGIC_APPLE
	MAGIC_NO_CHECK_APPTYPE Flag = C.MAGIC_NO_CHECK_APPTYPE
	MAGIC_NO_CHECK_CDF Flag = C.MAGIC_NO_CHECK_CDF
	MAGIC_NO_CHECK_COMPRESS Flag = C.MAGIC_NO_CHECK_COMPRESS
	MAGIC_NO_CHECK_ELF Flag = C.MAGIC_NO_CHECK_ELF
	MAGIC_NO_CHECK_ENCODING Flag = C.MAGIC_NO_CHECK_ENCODING
	MAGIC_NO_CHECK_SOFT Flag = C.MAGIC_NO_CHECK_SOFT
	MAGIC_NO_CHECK_TAR Flag = C.MAGIC_NO_CHECK_TAR
	MAGIC_NO_CHECK_TEXT Flag = C.MAGIC_NO_CHECK_TEXT
	MAGIC_NO_CHECK_TOKENS Flag = C.MAGIC_NO_CHECK_TOKENS
)
func NewDecoder(flags Flag) (*Decoder, error) {
	db := C.magic_open(C.int(0))
	if db == nil {
		return nil, errors.New("error opening magic")
	}
	d := &Decoder{db: db}
	if code := C.magic_setflags(db, C.int(flags)); code != 0 {
		d.Close()
		return nil, errors.New(C.GoString(C.magic_error(d.db)))
	}
	if code := C.magic_load(db, nil); code != 0 {
		d.Close()
		return nil, errors.New(C.GoString(C.magic_error(d.db)))
	}
	return d, nil
}
func (d *Decoder) TypeByFile(filename string) (string, error) {
	path := C.CString(filename)
	defer C.free(unsafe.Pointer(path))
	out := C.magic_file(d.db, path)
	if out == nil {
		return "", errors.New(C.GoString(C.magic_error(d.db)))
	}
	return C.GoString(out), nil
}