aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/file.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-05-10 16:47:15 +0200
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-05-23 11:05:14 +0200
commit2f293f4a5214ccba5bdf0b82ff8b62ed39144078 (patch)
tree8942869ff31dbf3aa950c1d3cddb3a0de8ca0aa3 /plumbing/object/file.go
parent2ff77a8d93529cefdca922dbed89d4b1cd0ee8e5 (diff)
downloadgo-git-2f293f4a5214ccba5bdf0b82ff8b62ed39144078.tar.gz
format/diff: unified diff encoder and public API
- Added Patch interface - Added a Unified Diff encoder from Patches - Added Change method to generate Patches - Added Changes method to generate Patches - Added Tree method to generate Patches - Added Commit method to generate Patches
Diffstat (limited to 'plumbing/object/file.go')
-rw-r--r--plumbing/object/file.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/plumbing/object/file.go b/plumbing/object/file.go
index 6932c31..79f57fe 100644
--- a/plumbing/object/file.go
+++ b/plumbing/object/file.go
@@ -7,6 +7,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
+ "gopkg.in/src-d/go-git.v4/utils/binary"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
@@ -42,6 +43,17 @@ func (f *File) Contents() (content string, err error) {
return buf.String(), nil
}
+// IsBinary returns if the file is binary or not
+func (f *File) IsBinary() (bool, error) {
+ reader, err := f.Reader()
+ if err != nil {
+ return false, err
+ }
+ defer ioutil.CheckClose(reader, &err)
+
+ return binary.IsBinary(reader)
+}
+
// Lines returns a slice of lines from the contents of a file, stripping
// all end of line characters. If the last line is empty (does not end
// in an end of line), it is also stripped.