Jens Geyer | 197b062 | 2017-05-31 10:35:00 +0200 | [diff] [blame] | 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.IO; |
| 4 | using System.Linq; |
| 5 | using System.Text; |
| 6 | |
| 7 | #if (!NET45) |
| 8 | namespace Thrift |
| 9 | { |
| 10 | static class StreamExtensionsNet35 |
| 11 | { |
| 12 | // CopyTo() has been added in 4.0 |
| 13 | public static long CopyTo(this Stream source, Stream target) |
| 14 | { |
| 15 | byte[] buffer = new byte[8192]; // multiple of 4096 |
| 16 | long nTotal = 0; |
| 17 | while (true) |
| 18 | { |
| 19 | int nRead = source.Read(buffer, 0, buffer.Length); |
| 20 | if (nRead <= 0) // done? |
| 21 | return nTotal; |
| 22 | |
| 23 | target.Write(buffer, 0, nRead); |
| 24 | nTotal += nRead; |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | } |
| 30 | #endif |
| 31 | |