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)
| 169 | // IsBinary detects if data is a binary value based on: |
| 170 | // http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198 |
| 171 | func IsBinary(r io.Reader) (bool, error) { |
| 172 | reader := bufio.NewReader(r) |
| 173 | c := 0 |
| 174 | for { |
| 175 | if c == sniffLen { |
| 176 | break |
| 177 | } |
| 178 | |
| 179 | b, err := reader.ReadByte() |
| 180 | if err == io.EOF { |
| 181 | break |
| 182 | } |
| 183 | if err != nil { |
| 184 | return false, err |
| 185 | } |
| 186 | |
| 187 | if b == byte(0) { |
| 188 | return true, nil |
| 189 | } |
| 190 | |
| 191 | c++ |
| 192 | } |
| 193 | |
| 194 | return false, nil |
| 195 | } |
searching dependent graphs…