public static void PrepareResume(long successfulLength, Stream successfulPart, HashAlgorithm hashAlg) {
byte[] buffer = new byte[4096];
int pos = 0;
while (pos < successfulLength) {
int l = successfulPart.Read(buffer, 0, (int)Math.Min(buffer.Length, successfulLength - pos));
if (l <= 0) {
throw new IOException(string.Format("File stream is shorter ({0}) than the given length {1}", pos, successfulLength));
}
hashAlg.TransformBlock(buffer, 0, l, buffer, 0);
pos += l;
}
}