Пример #1
0
// add adds extension, bytematcher or containermatcher signatures to the identifier
func (p *pronom) add(m core.Matcher, t core.MatcherType) error {
	switch t {
	default:
		return fmt.Errorf("Pronom: unknown matcher type %d", t)
	case core.ExtensionMatcher:
		if !config.NoExt() {
			var exts [][]string
			exts, p.ePuids = p.j.Globs()
			l, err := m.Add(stringmatcher.SignatureSet(exts), nil)
			if err != nil {
				return err
			}
			p.eStart = l - len(p.ePuids)
			return nil
		}
	case core.MIMEMatcher:
		if !config.NoMIME() {
			var mimes [][]string
			mimes, p.mPuids = p.j.MIMEs()
			l, err := m.Add(stringmatcher.SignatureSet(mimes), nil)
			if err != nil {
				return err
			}
			p.mStart = l - len(p.mPuids)
			return nil
		}
	case core.ContainerMatcher:
		return p.contMatcher(m)
	case core.ByteMatcher:
		var sigs []frames.Signature
		var err error
		sigs, p.bPuids, err = p.j.Signatures()
		if err != nil {
			return err
		}
		var plist priority.List
		if !config.NoPriority() {
			plist = p.pm.List(p.bPuids)
		}
		l, err := m.Add(bytematcher.SignatureSet(sigs), plist)
		if err != nil {
			return err
		}
		p.bStart = l - len(p.bPuids)
	case core.TextMatcher:
		if !config.NoText() && p.hasPuid(config.TextPuid()) {
			l, _ := m.Add(textmatcher.SignatureSet{}, nil)
			p.tStart = l
		}
	}
	return nil
}
Пример #2
0
// add adds extension, bytematcher or containermatcher signatures to the identifier
func (p *pronom) add(m core.Matcher) error {
	switch t := m.(type) {
	default:
		return fmt.Errorf("Pronom: unknown matcher type %T", t)
	case extensionmatcher.Matcher:
		if !config.NoExt() {
			var exts [][]string
			exts, p.ePuids = p.j.extensions()
			l, err := m.Add(extensionmatcher.SignatureSet(exts), nil)
			if err != nil {
				return err
			}
			p.eStart = l - len(p.ePuids)
			return nil
		}
	case containermatcher.Matcher:
		return p.contMatcher(m)
	case *bytematcher.Matcher:
		var sigs []frames.Signature
		var err error
		sigs, p.bPuids, err = p.j.signatures()
		if err != nil {
			return err
		}
		var plist priority.List
		if !config.NoPriority() {
			plist = p.pm.List(p.bPuids)
		}
		l, err := m.Add(bytematcher.SignatureSet(sigs), plist)
		if err != nil {
			return err
		}
		p.bStart = l - len(p.bPuids)
	case *textmatcher.Matcher:
		if !config.NoText() && p.hasPuid(config.TextPuid()) {
			l, _ := m.Add(textmatcher.SignatureSet{}, nil)
			p.tStart = l
		}
	}
	return nil
}