Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ImmutableMemoryStream.cs
Go to the documentation of this file.
2using System.IO;
3
5
6internal sealed class ImmutableMemoryStream : Stream
7{
8 private readonly ImmutableArray<byte> _array;
9
10 private int _position;
11
12 public override bool CanRead => true;
13
14 public override bool CanSeek => true;
15
16 public override bool CanWrite => false;
17
18 public override long Length => _array.Length;
19
20 public override long Position
21 {
22 get
23 {
24 return _position;
25 }
26 set
27 {
28 if (value < 0 || value >= _array.Length)
29 {
30 throw new ArgumentOutOfRangeException("value");
31 }
32 _position = (int)value;
33 }
34 }
35
40
42 {
43 return _array;
44 }
45
46 public override void Flush()
47 {
48 }
49
50 public override int Read(byte[] buffer, int offset, int count)
51 {
52 int num = Math.Min(count, _array.Length - _position);
54 _position += num;
55 return num;
56 }
57
58 public override long Seek(long offset, SeekOrigin origin)
59 {
60 long num;
61 try
62 {
63 num = checked(origin switch
64 {
65 SeekOrigin.Begin => offset,
66 SeekOrigin.Current => offset + _position,
67 SeekOrigin.End => offset + _array.Length,
68 _ => throw new ArgumentOutOfRangeException("origin"),
69 });
70 }
71 catch (OverflowException)
72 {
73 throw new ArgumentOutOfRangeException("offset");
74 }
75 if (num < 0 || num >= _array.Length)
76 {
77 throw new ArgumentOutOfRangeException("offset");
78 }
79 _position = (int)num;
80 return num;
81 }
82
83 public override void SetLength(long value)
84 {
85 throw new NotSupportedException();
86 }
87
88 public override void Write(byte[] buffer, int offset, int count)
89 {
90 throw new NotSupportedException();
91 }
92}
void ICollection. CopyTo(Array array, int index)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
override long Seek(long offset, SeekOrigin origin)
override int Read(byte[] buffer, int offset, int count)
override void Write(byte[] buffer, int offset, int count)