diff --git a/services/docextractor/plain.go b/services/docextractor/plain.go index cac6d06e1a..12393e2767 100644 --- a/services/docextractor/plain.go +++ b/services/docextractor/plain.go @@ -20,10 +20,15 @@ func (pe *plainExtractor) Extract(filename string, r io.ReadSeeker) (string, err // This detects any visible character plus any whitespace validRanges := append(unicode.GraphicRanges, unicode.White_Space) - text, _ := ioutil.ReadAll(r) + runes := make([]byte, 1028) + _, err := r.Read(runes) + if err != nil { + return "", err + } + count := 0 for { - c, size := utf8.DecodeRune(text[count:]) + c, size := utf8.DecodeRune(runes[count:]) if !unicode.In(c, validRanges...) { return "", nil } @@ -36,5 +41,6 @@ func (pe *plainExtractor) Extract(filename string, r io.ReadSeeker) (string, err } } + text, _ := ioutil.ReadAll(r) return string(text), nil }