Browse Source

Use ReadFull when reading chunks for torrent

When generating a torrent, we need to get the SHA1 hash of each chunk of
the file. Because we stream the data for S3, Read doesn't always fill
the chunk buffer, so to fix this, we can use ReadFull.
pull/156/head
mutantmonkey 6 years ago
parent
commit
0fc3fa9a45
  1. 7
      torrent.go

7
torrent.go

@ -28,10 +28,10 @@ func createTorrent(fileName string, f io.Reader, r *http.Request) ([]byte, error
} }
for { for {
n, err := f.Read(chunk)
n, err := io.ReadFull(f, chunk)
if err == io.EOF { if err == io.EOF {
break break
} else if err != nil {
} else if err != nil && err != io.ErrUnexpectedEOF {
return []byte{}, err return []byte{}, err
} }
@ -58,7 +58,8 @@ func fileTorrentHandler(c web.C, w http.ResponseWriter, r *http.Request) {
oopsHandler(c, w, r, RespAUTO, "Corrupt metadata.") oopsHandler(c, w, r, RespAUTO, "Corrupt metadata.")
return return
} else if err != nil { } else if err != nil {
oopsHandler(c, w, r, RespAUTO, "Could not create torrent.")
oopsHandler(c, w, r, RespAUTO, err.Error())
return
} }
defer f.Close() defer f.Close()

Loading…
Cancel
Save