Esempio n. 1
0
// update the absolute positional information (distance from the BOF or EOF)
// for keyFrames based on the other keyFrames in the signature
func updatePositions(ks []keyFrame) {
	var min, max int64
	// first forwards, for BOF and PREV
	for i := range ks {
		if ks[i].typ == frames.BOF {
			min, max = calcMinMax(0, 0, ks[i].seg)
			// Apply max bof
			if config.MaxBOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxBOF()) {
					ks[i].key.pMax = int64(config.MaxBOF())
				}
			}
		}
		if ks[i].typ == frames.PREV {
			ks[i].key.pMin = min + ks[i].key.pMin
			if max > -1 && ks[i].key.pMax > -1 {
				ks[i].key.pMax = max + ks[i].key.pMax
			} else {
				ks[i].key.pMax = -1
			}
			min, max = calcMinMax(min, max, ks[i].seg)
			// Apply max bof
			if config.MaxBOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxBOF()) {
					ks[i].key.pMax = int64(config.MaxBOF())
				}
			}
		}
	}
	// now backwards for EOF and SUCC
	min, max = 0, 0
	for i := len(ks) - 1; i >= 0; i-- {
		if ks[i].typ == frames.EOF {
			min, max = calcMinMax(0, 0, ks[i].seg)
			// apply max eof
			if config.MaxEOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxEOF()) {
					ks[i].key.pMax = int64(config.MaxEOF())
				}
			}
		}
		if ks[i].typ == frames.SUCC {
			ks[i].key.pMin = min + ks[i].key.pMin
			if max > -1 && ks[i].key.pMax > -1 {
				ks[i].key.pMax = max + ks[i].key.pMax
			} else {
				ks[i].key.pMax = -1
			}
			min, max = calcMinMax(min, max, ks[i].seg)
			// apply max eof
			if config.MaxEOF() > 0 {
				if ks[i].key.pMax < 0 || ks[i].key.pMax > int64(config.MaxEOF()) {
					ks[i].key.pMax = int64(config.MaxEOF())
				}
			}
		}
	}
}
Esempio n. 2
0
// set parseables joins signatures in the DROID signature file with any extra reports and adds that to the pronom object
func (p *pronom) setParseables() error {
	d, err := newDroid(config.Droid())
	if err != nil {
		return fmt.Errorf("Pronom: error loading Droid file; got %s\nYou must have a Droid file to build a signature", err)
	}
	// if we are just inspecting a single report file
	if config.Inspect() {
		r, err := newReports(config.Limit(d.IDs()), nil)
		if err != nil {
			return fmt.Errorf("Pronom: error loading reports; got %s\nYou must download PRONOM reports to build a signature (unless you use the -noreports flag). You can use `roy harvest` to download reports", err)
		}
		is := infos(r.Infos())
		sigs, puids, err := r.Signatures()
		if err != nil {
			return fmt.Errorf("Pronom: parsing signatures; got %s", err)
		}
		var puid string
		for i, sig := range sigs {
			if puids[i] != puid {
				puid = puids[i]
				fmt.Printf("%s: \n", is[puid].name)
			}
			fmt.Println(sig)
		}
		p.j = r
		return nil
	}
	// apply limit or exclude filters (only one can be applied)
	puids := d.IDs()
	if config.HasLimit() {
		puids = config.Limit(puids)
	} else if config.HasExclude() {
		puids = config.Exclude(puids)
	}
	// if noreports set
	if config.Reports() == "" {
		p.j = d
		// apply filter
		if config.HasLimit() || config.HasExclude() {
			p.j = parseable.Filter(puids, p.j)
		}
	} else { // otherwise build from reports
		r, err := newReports(puids, d.idsPuids())
		if err != nil {
			return fmt.Errorf("Pronom: error loading reports; got %s\nYou must download PRONOM reports to build a signature (unless you use the -noreports flag). You can use `roy harvest` to download reports", err)
		}
		p.j = r
	}
	// exclude byte signatures where also have container signatures, unless doubleup set
	if !config.DoubleUp() {
		p.j = &doublesFilter{
			config.ExcludeDoubles(puids, p.c.Puids()),
			p.j,
		}
	}
	// add extensions
	for _, v := range config.Extend() {
		e, err := newDroid(v)
		if err != nil {
			return fmt.Errorf("Pronom: error loading extension file; got %s", err)
		}
		p.j = parseable.Join(p.j, e)
	}
	// mirror PREV wild segments into EOF if maxBof and maxEOF set
	if config.MaxBOF() > 0 && config.MaxEOF() > 0 {
		p.j = &parseable.Mirror{p.j}
	}
	return nil
}