Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DownloadBits()

byte[] System.Net.WebClient.DownloadBits ( WebRequest request,
Stream writeStream )
inlineprivate

Definition at line 1034 of file WebClient.cs.

1035 {
1036 try
1037 {
1038 WebResponse webResponse = (_webResponse = GetWebResponse(request));
1039 long contentLength = webResponse.ContentLength;
1040 byte[] array = new byte[(contentLength == -1 || contentLength > 65536) ? 65536 : contentLength];
1041 if (writeStream is ChunkedMemoryStream)
1042 {
1043 if (contentLength > int.MaxValue)
1044 {
1045 throw new WebException(System.SR.net_webstatus_MessageLengthLimitExceeded, WebExceptionStatus.MessageLengthLimitExceeded);
1046 }
1047 writeStream.SetLength(array.Length);
1048 }
1049 using (Stream stream = webResponse.GetResponseStream())
1050 {
1051 if (stream != null)
1052 {
1053 int count;
1054 while ((count = stream.Read(array, 0, array.Length)) != 0)
1055 {
1056 writeStream.Write(array, 0, count);
1057 }
1058 }
1059 }
1060 return (writeStream as ChunkedMemoryStream)?.ToArray();
1061 }
1062 catch (Exception ex) when (!(ex is OutOfMemoryException))
1063 {
1064 writeStream?.Close();
1065 AbortRequest(request);
1066 if (ex is WebException || ex is SecurityException)
1067 {
1068 throw;
1069 }
1070 throw new WebException(System.SR.net_webclient, ex);
1071 }
1072 }
void SetLength(long value)
virtual void Close()
Definition Stream.cs:644
void Write(byte[] buffer, int offset, int count)
virtual WebResponse GetWebResponse(WebRequest request)
Definition WebClient.cs:455
WebResponse _webResponse
Definition WebClient.cs:74
static void AbortRequest(WebRequest request)
Definition WebClient.cs:929
static string net_webclient
Definition SR.cs:14
static string net_webstatus_MessageLengthLimitExceeded
Definition SR.cs:24
Definition SR.cs:7

References System.Net.WebClient._webResponse, System.Net.WebClient.AbortRequest(), System.array, System.IO.Stream.Close(), System.Net.WebResponse.ContentLength, System.count, System.Net.WebResponse.GetResponseStream(), System.Net.WebClient.GetWebResponse(), System.SR.net_webclient, System.SR.net_webstatus_MessageLengthLimitExceeded, System.IO.Stream.SetLength(), System.stream, and System.IO.Stream.Write().

Referenced by System.Net.WebClient.DownloadDataInternal(), System.Net.WebClient.DownloadFile(), and System.Net.WebClient.UploadBits().