Пример #1
0
func (r *Reader) readOFSDelta(raw core.Object, steps int64) error {
	start := r.r.position
	offset, err := decodeOffset(r.r, steps)
	if err != nil {
		return err
	}

	buf := bytes.NewBuffer(nil)
	if err := r.inflate(buf); err != nil {
		return err
	}

	ref, ok := r.offsets[start+offset]
	if !ok {
		return PackEntryNotFoundErr.n("offset %d", start+offset)
	}

	referenced, _ := r.s.Get(ref)
	d, _ := ioutil.ReadAll(referenced.Reader())
	patched := patchDelta(d, buf.Bytes())
	if patched == nil {
		return PatchingErr.n("hash %q", ref)
	}

	raw.SetType(referenced.Type())
	raw.SetSize(int64(len(patched)))
	raw.Writer().Write(patched)

	return nil
}
Пример #2
0
func (r *Reader) readREFDelta(raw core.Object) error {
	var ref core.Hash
	if _, err := r.r.Read(ref[:]); err != nil {
		return err
	}

	buf := bytes.NewBuffer(nil)
	if err := r.inflate(buf); err != nil {
		return err
	}

	referenced, ok := r.s.Get(ref)
	if !ok {
		return ObjectNotFoundErr.n("%s", ref)
	}

	d, _ := ioutil.ReadAll(referenced.Reader())
	patched := patchDelta(d, buf.Bytes())
	if patched == nil {
		return PatchingErr.n("hash %q", ref)
	}

	raw.SetType(referenced.Type())
	raw.SetSize(int64(len(patched)))
	raw.Writer().Write(patched)

	return nil
}