Skip to content

Instantly share code, notes, and snippets.

@habibg1232191
Created July 26, 2021 17:58
Show Gist options
  • Save habibg1232191/3183b7820984cf189a890bb19ac1586a to your computer and use it in GitHub Desktop.
Save habibg1232191/3183b7820984cf189a890bb19ac1586a to your computer and use it in GitHub Desktop.
HttpWebRequest checkedRequest = (HttpWebRequest) WebRequest.Create(remoteFilename);
HttpWebResponse checkedResponse = (HttpWebResponse) checkedRequest.GetResponse();
FileStream fs = new FileStream(localFilename, FileMode.OpenOrCreate);
request = (HttpWebRequest)WebRequest.Create(remoteFilename);
if (fs.Length < checkedResponse.ContentLength && fs.Length != 0)
{
request.Headers.Add("range", $"bytes={fs.Length}-");
}
response = (HttpWebResponse)request.GetResponse();
long downloadFileSize = response.ContentLength;
Stream s = response.GetResponseStream();
long startNumByte = 0;
if (fs.Length != 0)
startNumByte = fs.Length;
Console.WriteLine(((double) (checkedResponse.ContentLength - fs.Length) / 1024 / 1024).ToString("0.0 МБ"));
Byte[] read = new byte[checkedResponse.ContentLength - fs.Length];
long iRunningByteTotal = startNumByte;
int count = s.Read(read, 0, 1024);
iRunningByteTotal += count;
long totalSize = checkedResponse.ContentLength;
while (count > 0)
{
fs.Write(read, 0, count);
count = s.Read(read, 0, 1024);
iRunningByteTotal += count;
}
fs.Close();
s.Close();
response.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment