Closed glyn closed 6 years ago
This is really interesting problem! Thanks for raising.
Having thought about this at length, the issue might be outside the scope of this package. Grab doesn't offer any correctness/consistency guarantees above those offered by the standard net/http
library.
You might consider using the checksum feature. It means you waste time downloading a corrupted file, but it will throw an error.
Alternatively, you could implement some "progress snapshots" in your application. Maybe performing a checksum when you pause a download, storing it, and then checking the partial file again before you resume.
Finally, I'd suggest that if two applications are writing to the same file, causing this kind of corruption, there may be a design flaw.
Thanks for the feedback Ryan. If you have a few minutes, it may be worth documenting the restriction of this issue so that others don't fall into the same trap. They won't necessarily think to look in closed issues.
(We didn't use Grab in the end because of this restriction.)
Thanks for the feedback. I've added a 'Design trade-offs' section to the README. It's a little verbose, but hopefully makes this situation more clear.
I'm curious to learn how you solved the issue of resuming files when the local copied had been modified outside grab?
Readme update: 9a33a2e
Thanks for the README update @cavaliercoder!
I'm curious to learn how you solved the issue of resuming files when the local copied had been modified outside grab?
IIRC (and 6 months is a long time!) we check the checksum at the end so we can't end up using an invalid download.
Grab looked like a good fit for a project I'm working on so I gave it a spin. I found that it downloaded a file perfectly and when asked to download the same file again managed to avoid downloading all the bytes again, which was just what I was looking for.
I then overwrote the downloaded file with completely different contents and then downloaded again using grab. The message:
was emitted and the download was apparently successful. The downloaded file even had the same number of bytes as the original, but unfortunately the contents were corrupted.
Fortunately, this problem is easily reproduced using the example program in the README:
The environment is go version go1.9.2 darwin/amd64 on macOS 10.13.1.
In case the README changes, the contents of main.go above is: