diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-09-15 18:05:35 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-09-15 19:34:30 +0200 |
| commit | 712de1c63d9db97c81af68cd0dc4372c53d2e57a (patch) | |
| tree | ae1761fec52c3ae4ddd003a4130ddbda8d0a2d69 /vendor/github.com/shazow/go-diff/difflib/differ.go | |
| parent | 298a69c38dd5c8a9bbd7a022e88f4ddbcf885e16 (diff) | |
vendor/github.com/golangci/golangci-lint: update to v1.31
Diffstat (limited to 'vendor/github.com/shazow/go-diff/difflib/differ.go')
| -rw-r--r-- | vendor/github.com/shazow/go-diff/difflib/differ.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/shazow/go-diff/difflib/differ.go b/vendor/github.com/shazow/go-diff/difflib/differ.go new file mode 100644 index 000000000..43dc84d9a --- /dev/null +++ b/vendor/github.com/shazow/go-diff/difflib/differ.go @@ -0,0 +1,39 @@ +// This package implements the diff.Differ interface using github.com/mb0/diff as a backend. +package difflib + +import ( + "io" + "io/ioutil" + + "github.com/pmezard/go-difflib/difflib" +) + +type differ struct{} + +// New returns an implementation of diff.Differ using mb0diff as the backend. +func New() *differ { + return &differ{} +} + +// 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) +} |
