Skip to content

Commit

Permalink
Duplicate content for small text to have better encoding detection
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Sep 29, 2018
1 parent 5c4dac7 commit fab01bb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ func DetectEncoding(content []byte) (string, error) {
return "UTF-8", nil
}

result, err := chardet.NewTextDetector().DetectBest(content)
var detectContent []byte
if len(content) < 1024 {
times := 1024 / len(content)
detectContent = make([]byte, 0, times*len(content))
for i := 0; i < times; i++ {
detectContent = append(detectContent, content...)
}
} else {
detectContent = content
}
result, err := chardet.NewTextDetector().DetectBest(detectContent)
if err != nil {
return "", err
}
Expand Down

0 comments on commit fab01bb

Please sign in to comment.