Created
July 26, 2021 17:58
-
-
Save habibg1232191/3183b7820984cf189a890bb19ac1586a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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