From ff46a72f5317599c403f23a1a892fd746ffee91f Mon Sep 17 00:00:00 2001 From: Arseny Balobanov Date: Thu, 23 Apr 2020 19:42:40 +0300 Subject: [PATCH] io-lecture: replace f.Read(...) with io.ReadAtLeast(f, ...) in http chunking solution --- lectures/09-io/sendfile/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lectures/09-io/sendfile/main.go b/lectures/09-io/sendfile/main.go index f2608ec..69e3678 100644 --- a/lectures/09-io/sendfile/main.go +++ b/lectures/09-io/sendfile/main.go @@ -40,8 +40,8 @@ func copyHandler(w http.ResponseWriter, r *http.Request) { defer func() { _ = f.Close() }() // Infer the Content-Type of the file. - filePrefix := make([]byte, 512) - _, _ = f.Read(filePrefix) + filePrefix := make([]byte, 1024) + _, _ = io.ReadAtLeast(f, filePrefix, 512) contentType := http.DetectContentType(filePrefix) // Get the file size.