isText reports whether the first MB read from rs is valid UTF-8 text.
(rs io.ReadSeeker)
| 379 | |
| 380 | // isText reports whether the first MB read from rs is valid UTF-8 text. |
| 381 | func isText(rs io.ReadSeeker) (ok bool, err error) { |
| 382 | defer func() { |
| 383 | if _, seekErr := rs.Seek(0, io.SeekStart); seekErr != nil { |
| 384 | if err == nil { |
| 385 | err = seekErr |
| 386 | } |
| 387 | } |
| 388 | }() |
| 389 | var buf bytes.Buffer |
| 390 | if _, err := io.CopyN(&buf, rs, 1e6); err != nil { |
| 391 | if err != io.EOF { |
| 392 | return false, err |
| 393 | } |
| 394 | } |
| 395 | return utf8.Valid(buf.Bytes()), nil |
| 396 | } |
| 397 | |
| 398 | // statFiles stats the given refs and returns an error if any one of them is not |
| 399 | // found. |