[Modify] Polish it
This commit is contained in:
		| @@ -205,15 +205,6 @@ namespace WebSocketSharp | |||||||
|         action (); |         action (); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static bool writeTo (this Stream stream, Stream destination, int length, byte[] buffer) |  | ||||||
|     { |  | ||||||
|       var bytes = stream.readBytes (buffer, 0, length); |  | ||||||
|       var len = bytes.Length; |  | ||||||
|       destination.Write (bytes, 0, len); |  | ||||||
|  |  | ||||||
|       return len == length; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     #endregion |     #endregion | ||||||
|  |  | ||||||
|     #region Internal Methods |     #region Internal Methods | ||||||
| @@ -606,20 +597,23 @@ namespace WebSocketSharp | |||||||
|     internal static byte[] ReadBytes (this Stream stream, long length, int bufferLength) |     internal static byte[] ReadBytes (this Stream stream, long length, int bufferLength) | ||||||
|     { |     { | ||||||
|       using (var dest = new MemoryStream ()) { |       using (var dest = new MemoryStream ()) { | ||||||
|         var cnt = length / bufferLength; |         try { | ||||||
|         var rem = (int) (length % bufferLength); |           var buff = new byte[bufferLength]; | ||||||
|  |           var nread = 0; | ||||||
|  |           while (length > 0) { | ||||||
|  |             if (length < bufferLength) | ||||||
|  |               bufferLength = (int) length; | ||||||
|  |  | ||||||
|         var buff = new byte[bufferLength]; |             nread = stream.Read (buff, 0, bufferLength); | ||||||
|         var end = false; |             if (nread == 0) | ||||||
|         for (long i = 0; i < cnt; i++) { |               break; | ||||||
|           if (!stream.writeTo (dest, bufferLength, buff)) { |  | ||||||
|             end = true; |             dest.Write (buff, 0, nread); | ||||||
|             break; |             length -= nread; | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|  |         catch { | ||||||
|         if (!end && rem > 0) |         } | ||||||
|           stream.writeTo (dest, rem, new byte[rem]); |  | ||||||
|  |  | ||||||
|         dest.Close (); |         dest.Close (); | ||||||
|         return dest.ToArray (); |         return dest.ToArray (); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user