func New(opts ...config.Option) (core.Identifier, error) { for _, v := range opts { v() } loc, err := newLOC(config.LOC()) if err != nil { return nil, err } // set updated updated := loc.(fdds).Updated().Format(dateFmt) // add extensions for _, v := range config.Extend() { e, err := newLOC(v) if err != nil { return nil, fmt.Errorf("LOC: error loading extension file %s; got %s", v, err) } loc = identifier.Join(loc, e) } // apply config loc = identifier.ApplyConfig(loc) // return identifier return &Identifier{ infos: infos(loc.Infos()), Base: identifier.New(loc, config.ZipLOC(), updated), }, nil }
func (r *Recorder) Record(m core.MatcherType, res core.Result) bool { switch m { default: return false case core.NameMatcher: if hit, id := r.Hit(m, res.Index()); hit { r.ids = add(r.ids, r.Name(), id, r.infos[id], res.Basis(), extScore) return true } else { return false } case core.MIMEMatcher: if hit, id := r.Hit(m, res.Index()); hit { r.ids = add(r.ids, r.Name(), id, r.infos[id], res.Basis(), mimeScore) return true } else { return false } case core.ContainerMatcher: // add zip default if res.Index() < 0 { if r.ZipDefault() { r.cscore += incScore r.ids = add(r.ids, r.Name(), config.ZipLOC(), r.infos[config.ZipLOC()], res.Basis(), r.cscore) } return false } if hit, id := r.Hit(m, res.Index()); hit { r.cscore += incScore basis := res.Basis() p, t := r.Place(core.ContainerMatcher, res.Index()) if t > 1 { basis = basis + fmt.Sprintf(" (signature %d/%d)", p, t) } r.ids = add(r.ids, r.Name(), id, r.infos[id], basis, r.cscore) return true } else { return false } case core.RIFFMatcher: if hit, id := r.Hit(m, res.Index()); hit { if r.satisfied { return true } r.cscore += incScore r.ids = add(r.ids, r.Name(), id, r.infos[id], res.Basis(), r.cscore) return true } else { return false } case core.ByteMatcher: if hit, id := r.Hit(m, res.Index()); hit { if r.satisfied { return true } r.cscore += incScore basis := res.Basis() p, t := r.Place(core.ByteMatcher, res.Index()) if t > 1 { basis = basis + fmt.Sprintf(" (signature %d/%d)", p, t) } r.ids = add(r.ids, r.Name(), id, r.infos[id], basis, r.cscore) return true } else { return false } } }