isBinary reports whether data looks like binary content. It checks for null bytes in the first 8KB, which is the same heuristic git uses.
(data []byte)
| 288 | // isBinary reports whether data looks like binary content. |
| 289 | // It checks for null bytes in the first 8KB, which is the same heuristic git uses. |
| 290 | func isBinary(data []byte) bool { |
| 291 | check := data |
| 292 | if len(check) > 8192 { |
| 293 | check = check[:8192] |
| 294 | } |
| 295 | for _, b := range check { |
| 296 | if b == 0 { |
| 297 | return true |
| 298 | } |
| 299 | } |
| 300 | return false |
| 301 | } |
| 302 | |
| 303 | // countLines returns the number of lines in content, handling trailing newlines correctly. |
| 304 | func countLines(content string) int { |