From a0194899c922263911c19eed6f9734f53d22bc81 Mon Sep 17 00:00:00 2001 From: chinglin Date: Sun, 9 Sep 2018 02:01:41 +0800 Subject: [PATCH] fix: recognize small text files (#531) --- lib/file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/file.go b/lib/file.go index 2fb19425..8501fb6d 100644 --- a/lib/file.go +++ b/lib/file.go @@ -223,14 +223,14 @@ func (i *File) GetFileType(checkContent bool) error { // Only the first 512 bytes are used to sniff the content type. buffer := make([]byte, 512) - _, err = file.Read(buffer) + n, err := file.Read(buffer) if err != nil && err != io.EOF { return err } // Tries to get the file mimetype using its first // 512 bytes. - mimetype = http.DetectContentType(buffer) + mimetype = http.DetectContentType(buffer[:n]) } if strings.HasPrefix(mimetype, "video") {