Есть вот такой код:
public int Download(Stream stream)
{
stopped = false;
lastErrorCode = DOWNLOAD_ERROR_UNKNOWN;
streamSize = stream.Length;
bytesTranfered = 0;
HttpWebResponse response;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
if (rangeTo > 0)
request.AddRange(rangeFrom, rangeTo);
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse httpWebResponse = (HttpWebResponse)e.Response;
lastErrorCode = (int)httpWebResponse.StatusCode;
return lastErrorCode;
}
else
{
lastErrorCode = 400;
return 400;
}
}
catch (Exception)
{
lastErrorCode = 400;
return 400;
}
Stream responseStream = response.GetResponseStream();
long size = response.ContentLength;
WorkStart?.Invoke(this, size);
byte[] buf = new byte[4096];
int bytesRead;
long bytesAvaliable;
lastErrorCode = 200;
int iter = 0;
try
{
do
{
bytesAvaliable = size - bytesTranfered;
if (bytesAvaliable > 0)
{
bytesRead = responseStream.Read(buf, 0, buf.Length);
if (bytesRead > 0)
{
stream.Write(buf, 0, bytesRead);
bytesTranfered += bytesRead;
if (WorkProgress != null && (progressUpdateInterval == 0 || iter++ >= progressUpdateInterval))
{
WorkProgress.Invoke(this, bytesTranfered, ref stopped);
iter = 0;
}
}
}
}
while (bytesAvaliable > 0 && !stopped);
}
catch (Exception)
{
lastErrorCode = DOWNLOAD_ERROR_UNKNOWN;
}
response.Close();
response.Dispose();
if (stopped)
{
lastErrorCode = DOWNLOAD_ERROR_ABORTED_BY_USER;
}
else
if (lastErrorCode != DOWNLOAD_ERROR_UNKNOWN)
{
if (size != 0 && bytesTranfered != size)
lastErrorCode = DOWNLOAD_ERROR_INCOMPLETE_DATA_READ;
}
WorkEnd?.Invoke(this, bytesTranfered, lastErrorCode);
return lastErrorCode;
}
Как его изменить, чтобы качалось не в стрим, а в string
?