mikehearn/PayFile — pull request #5 by simondlr (2013-11-20 14:12:14+00:00)
Title: Fix bugs where user could not download the same file again.

2 things were going wrong here. They both boil down to the fact that a File wasn't being reset properly after it was downloaded.

It's downloadStream, bytesDownloaded and nextChunk should be reset once it is done. So that if a user wants to download it again, they can do so (and so that it doesn't give an error).

If only downloadStream is reset, then downloading the file again asks for a chunk that isn't there (ie, as if it is has been done downloading).

I'm not entirely sure why completionFuture is checking for an exception? Even if there was an exception, to my mind, the downloadStream should be reset either way (for now at least). (Is there some way to code this to resume a download in the future? It seems it will only work for if client and server can specifically opt to 'pause'),

Also, I think perhaps all the reset code should be in whenComplete (along with resetBytes and resetNextChunk)?