Example #1
0
func New() (*Magic, error) {
	db := C.magic_open(C.int(0))
	C.magic_setflags(db, C.int(C.MAGIC_SYMLINK|C.MAGIC_ERROR))
	if code := C.magic_load(db, nil); code != 0 {
		return nil, errors.New(C.GoString(C.magic_error(db)))
	}
	return &Magic{db}, nil
}
Example #2
0
// SetFlags sets the given flags.
//
// Note that using both MIME flags together can also return extra
// information on the charset.
func (m *Magic) SetFlags(flags int) error {
	if m.ptr == nil {
		return ConnectionError
	}

	if C.magic_setflags(m.ptr, C.int(flags)) < 0 {
		return errors.New("Magic: FlagPreserveATime is not supported by this system.")
	}

	return m.check()
}
Example #3
0
func New(flags MagicFlag) (*Magic, error) {
	db := C.magic_open(C.int(0))
	if db == nil {
		return nil, errors.New("Error allocating magic cookie")
	}

	if code := C.magic_setflags(db, C.int(flags)); code != 0 {
		return nil, errors.New(C.GoString(C.magic_error(db)))
	}

	if code := C.magic_load(db, nil); code != 0 {
		return nil, errors.New(C.GoString(C.magic_error(db)))
	}

	return &Magic{db}, nil
}
Example #4
0
func Open(flags MagicFlag) error {
	db = C.magic_open(C.int(0))
	if db == nil {
		return errors.New("error opening magic")
	}

	if code := C.magic_setflags(db, C.int(flags)); code != 0 {
		return errors.New(C.GoString(C.magic_error(db)))
	}

	if code := C.magic_load(db, nil); code != 0 {
		return errors.New(C.GoString(C.magic_error(db)))
	}

	return nil
}
Example #5
0
// NewDecoder creates a detector that uses libmagic. It initializes
// the opens the magicmime database with the specified flags. Upon
// success users are expected to call Close on the returned Decoder
// when it is no longer needed.
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
}
Example #6
0
func SetFlags(cookie Magic_t, flags int) int {
	return (int)(C.magic_setflags(cookie, C.int(flags)))
}