melbahja / got

Got: Simple golang package and CLI tool to download large files faster 🏃 than cURL and Wget!
MIT License
709 stars 45 forks source link

download file content is not valid if use ChunkSize is bigger than the file content size #68

Open simonwu-os opened 1 year ago

simonwu-os commented 1 year ago

I use --chunk 5242880 to specify ChunkSize.
If the size of the target file is less then 5M, the content downloaded is not valid. Its sha256 is not right. I check the source code, I find it has a bug. When d.info.Size is less than d.ChunkSize, then chunksLen is zero.

I fix it in my fork https://github.com/simonwu-os/got. It works fine.

chunksLen := d.info.Size / d.ChunkSize ///added by simon wu ///fix if chunksLen = 0, then the result file content is not valid. if chunksLen == 0 { chunksLen += 1 } ///end of added