Exemplo n.º 1
0
// Diff consumes the entire reader streams into memory before generating a diff
// which then gets filled into the buffer. This implementation stores and
// manipulates all three values in memory.
func (diff *differ) Diff(out io.Writer, a io.ReadSeeker, b io.ReadSeeker) error {
	var src, dst []byte
	var err error

	if src, err = ioutil.ReadAll(a); err != nil {
		return err
	}
	if dst, err = ioutil.ReadAll(b); err != nil {
		return err
	}

	d := difflib.UnifiedDiff{
		A:       difflib.SplitLines(string(src)),
		B:       difflib.SplitLines(string(dst)),
		Context: 3,
	}

	return difflib.WriteUnifiedDiff(out, d)
}
Exemplo n.º 2
0
func (t *ZkLiveTree) diffNode(node *ZkNode) error {
	log.Printf("diff node @ `%s`", node.Path)

	diff := difflib.UnifiedDiff{
		FromFile: "a" + node.Path,
		ToFile:   "b" + node.Path,
		Context:  3,
	}

	if data, err := t.client.GetData().ForPath(node.Path); err == nil {
		diff.A = difflib.SplitLines(node.Value)
		diff.B = difflib.SplitLines(string(data))
	} else if err == curator.ErrNoNode {
		diff.A = difflib.SplitLines(node.Value)
	} else {
		return err
	}

	if err := difflib.WriteUnifiedDiff(os.Stdout, diff); err != nil {
		return err
	}

	return nil
}