bentonstark / starksoft-aspen

.net / mono security and cryptography library that provides client support for ftps, gnupg, smartcard, and socks / http proxies
106 stars 49 forks source link

TransferBytes resume issue #13

Closed matteomonizza closed 8 years ago

matteomonizza commented 9 years ago

The function ignores the resume start position and so the TransferProgressEventArgs values aren't right (percent complete, time remaining...)

bentonstark commented 8 years ago

I am not sure I can fix this for all cases. The problem is that I would need to know the total size of the file being transferred but that is not always the case with streams. A stream may just contain a chunk of a file and not the entire transfer. I just know the current position and if the stream gives accurate data the length of the stream. Below is the patch that will fix the common cases.

// set the transfer size so we can do some calc on percentage completed
// in the TransferBytes() method of the base class
if (IsTranferProgressEventSet() && inputStream.CanSeek) {
            // if the transfer is a resume then subtract the current position from the length
            if (action == FileAction.Resume || action == FileAction.ResumeOrCreate) {
                SetTransferSize (inputStream.Length - inputStream.Position);
            } else {
                SetTransferSize (inputStream.Length);
            }
        }
bentonstark commented 8 years ago

Added change to latest version which will get pushed today.