DetectEncoding returns best guess of encoding of given content.
(content []byte)
| 31 | |
| 32 | // DetectEncoding returns best guess of encoding of given content. |
| 33 | func DetectEncoding(content []byte) (string, error) { |
| 34 | if utf8.Valid(content) { |
| 35 | log.Trace("Detected encoding: UTF-8 (fast)") |
| 36 | return "UTF-8", nil |
| 37 | } |
| 38 | |
| 39 | result, err := chardet.NewTextDetector().DetectBest(content) |
| 40 | if result.Charset != "UTF-8" && len(conf.Repository.ANSICharset) > 0 { |
| 41 | log.Trace("Using default ANSICharset: %s", conf.Repository.ANSICharset) |
| 42 | return conf.Repository.ANSICharset, err |
| 43 | } |
| 44 | |
| 45 | log.Trace("Detected encoding: %s", result.Charset) |
| 46 | return result.Charset, err |
| 47 | } |
| 48 | |
| 49 | // BasicAuthDecode decodes username and password portions of HTTP Basic Authentication |
| 50 | // from encoded content. |
no outgoing calls
no test coverage detected