Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SubReadStream.cs
Go to the documentation of this file.
4
6
7internal sealed class SubReadStream : Stream
8{
9 private readonly long _startInSuperStream;
10
12
13 private readonly long _endInSuperStream;
14
15 private readonly Stream _superStream;
16
17 private bool _canRead;
18
19 private bool _isDisposed;
20
21 public override long Length
22 {
23 get
24 {
27 }
28 }
29
30 public override long Position
31 {
32 get
33 {
36 }
37 set
38 {
41 }
42 }
43
44 public override bool CanRead
45 {
46 get
47 {
49 {
50 return _canRead;
51 }
52 return false;
53 }
54 }
55
56 public override bool CanSeek => false;
57
58 public override bool CanWrite => false;
59
60 public SubReadStream(Stream superStream, long startPosition, long maxLength)
61 {
62 _startInSuperStream = startPosition;
63 _positionInSuperStream = startPosition;
64 _endInSuperStream = startPosition + maxLength;
65 _superStream = superStream;
66 _canRead = true;
67 _isDisposed = false;
68 }
69
70 private void ThrowIfDisposed()
71 {
72 if (_isDisposed)
73 {
75 }
76 }
77
78 private void ThrowIfCantRead()
79 {
80 if (!CanRead)
81 {
83 }
84 }
85
86 public override int Read(byte[] buffer, int offset, int count)
87 {
88 int num = count;
92 {
94 }
96 {
98 }
99 int num2 = _superStream.Read(buffer, offset, count);
101 return num2;
102 }
103
104 public override int Read(Span<byte> destination)
105 {
106 int length = destination.Length;
107 int num = destination.Length;
111 {
113 }
115 {
117 }
118 int num2 = _superStream.Read(destination.Slice(0, num));
120 return num2;
121 }
122
123 public override int ReadByte()
124 {
125 byte reference = 0;
126 if (Read(MemoryMarshal.CreateSpan(ref reference, 1)) != 1)
127 {
128 return -1;
129 }
130 return reference;
131 }
132
138
159
160 public override long Seek(long offset, SeekOrigin origin)
161 {
164 }
165
166 public override void SetLength(long value)
167 {
170 }
171
172 public override void Write(byte[] buffer, int offset, int count)
173 {
176 }
177
178 public override void Flush()
179 {
182 }
183
184 protected override void Dispose(bool disposing)
185 {
186 if (disposing && !_isDisposed)
187 {
188 _canRead = false;
189 _isDisposed = true;
190 }
191 base.Dispose(disposing);
192 }
193}
override void SetLength(long value)
override int Read(byte[] buffer, int offset, int count)
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
SubReadStream(Stream superStream, long startPosition, long maxLength)
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
override void Write(byte[] buffer, int offset, int count)
override long Seek(long offset, SeekOrigin origin)
override void Dispose(bool disposing)
override int Read(Span< byte > destination)
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
Definition Stream.cs:1044
long Seek(long offset, SeekOrigin origin)
int Read(byte[] buffer, int offset, int count)
Task< int > ReadAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:762
static string SeekingNotSupported
Definition SR.cs:114
static string SetLengthRequiresSeekingAndWriting
Definition SR.cs:116
static string ReadingNotSupported
Definition SR.cs:108
static string WritingNotSupported
Definition SR.cs:130
static string HiddenStreamName
Definition SR.cs:100
Definition SR.cs:7
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226