io-lecture: replace f.Read(...) with io.ReadAtLeast(f, ...) in http chunking solution

This commit is contained in:
Arseny Balobanov 2020-04-23 19:42:40 +03:00
parent 9f02fb6a2b
commit ff46a72f53

View file

@ -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.