Skip to content

Commit a019489

Browse files
chinglinwen1138-4EB
authored andcommitted
fix: recognize small text files (filebrowser#531)
1 parent 43707a6 commit a019489

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ func (i *File) GetFileType(checkContent bool) error {
223223

224224
// Only the first 512 bytes are used to sniff the content type.
225225
buffer := make([]byte, 512)
226-
_, err = file.Read(buffer)
226+
n, err := file.Read(buffer)
227227
if err != nil && err != io.EOF {
228228
return err
229229
}
230230

231231
// Tries to get the file mimetype using its first
232232
// 512 bytes.
233-
mimetype = http.DetectContentType(buffer)
233+
mimetype = http.DetectContentType(buffer[:n])
234234
}
235235

236236
if strings.HasPrefix(mimetype, "video") {

0 commit comments

Comments
 (0)