IsBinary detects if data is a binary value based on: http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198
(r io.Reader)
| 154 | // IsBinary detects if data is a binary value based on: |
| 155 | // http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198 |
| 156 | func IsBinary(r io.Reader) (bool, error) { |
| 157 | reader := bufio.NewReader(r) |
| 158 | c := 0 |
| 159 | for { |
| 160 | if c == sniffLen { |
| 161 | break |
| 162 | } |
| 163 | |
| 164 | b, err := reader.ReadByte() |
| 165 | if err == io.EOF { |
| 166 | break |
| 167 | } |
| 168 | if err != nil { |
| 169 | return false, err |
| 170 | } |
| 171 | |
| 172 | if b == byte(0) { |
| 173 | return true, nil |
| 174 | } |
| 175 | |
| 176 | c++ |
| 177 | } |
| 178 | |
| 179 | return false, nil |
| 180 | } |