(content: &[u8])
| 457 | } |
| 458 | |
| 459 | fn is_binary(content: &[u8]) -> bool { |
| 460 | if content.is_empty() { |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | let check_len = std::cmp::min(4096, content.len()); |
| 465 | let bytes = &content[..check_len]; |
| 466 | |
| 467 | if bytes.contains(&0) { |
| 468 | return true; |
| 469 | } |
| 470 | |
| 471 | let non_printable = bytes |
| 472 | .iter() |
| 473 | .filter(|&&b| b < 9 || (b > 13 && b < 32)) |
| 474 | .count(); |
| 475 | |
| 476 | non_printable as f32 / check_len as f32 > 0.3 |
| 477 | } |
| 478 | |
| 479 | struct InstructionPrompt { |
| 480 | filepath: String, |