Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StreamExtensions.cs
Go to the documentation of this file.
1using System.IO;
3
5
6internal static class StreamExtensions
7{
8 internal const int StreamCopyBufferSize = 81920;
9
10 internal unsafe static void CopyTo(this Stream source, byte* destination, int size)
11 {
12 byte[] array = new byte[Math.Min(81920, size)];
13 while (size > 0)
14 {
15 int num = Math.Min(size, array.Length);
16 int num2 = source.Read(array, 0, num);
17 if (num2 <= 0 || num2 > num)
18 {
20 }
22 destination += num2;
23 size -= num2;
24 }
25 }
26
27 internal static int TryReadAll(this Stream stream, byte[] buffer, int offset, int count)
28 {
29 int i;
30 int num;
31 for (i = 0; i < count; i += num)
32 {
33 num = stream.Read(buffer, offset + i, count - i);
34 if (num == 0)
35 {
36 break;
37 }
38 }
39 return i;
40 }
41
42 internal static int TryReadAll(this Stream stream, Span<byte> buffer)
43 {
44 int i;
45 int num;
46 for (i = 0; i < buffer.Length; i += num)
47 {
48 num = stream.Read(buffer.Slice(i));
49 if (num == 0)
50 {
51 break;
52 }
53 }
54 return i;
55 }
56
57 internal static int GetAndValidateSize(Stream stream, int size, string streamParameterName)
58 {
59 long num = stream.Length - stream.Position;
60 if (size < 0 || size > num)
61 {
62 throw new ArgumentOutOfRangeException("size");
63 }
64 if (size != 0)
65 {
66 return size;
67 }
68 if (num > int.MaxValue)
69 {
70 throw new ArgumentException(System.SR.StreamTooLarge, streamParameterName);
71 }
72 return (int)num;
73 }
74}
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static int TryReadAll(this Stream stream, Span< byte > buffer)
static unsafe void CopyTo(this Stream source, byte *destination, int size)
static int TryReadAll(this Stream stream, byte[] buffer, int offset, int count)
static int GetAndValidateSize(Stream stream, int size, string streamParameterName)
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static string StreamTooLarge
Definition SR.cs:122
static string UnexpectedStreamEnd
Definition SR.cs:98
Definition SR.cs:7