public static void ReadAll(int bufferSize) { var buffer = new byte[bufferSize]; var sb = new StringBuilder(); while (true) { var read = Stream.Read(buffer, 0, buffer.Length); if (read == 0) { break; } sb.Append(Encoding.ASCII.GetChars(buffer, 0, read)); } Result = sb.ToString(); }
public async Task Reading() { var m1 = new byte[] { 1, 2, 3, 4 }; var m2 = new byte[m1.Length]; var stream = new Substream(); stream.AddData(new byte[] { 1, 2 }); stream.AddData(new byte[] { 3, 4 }); stream.NoMoreData(); Assert.IsTrue(stream.CanRead); m2[0] = (byte)stream.ReadByte(); Assert.AreEqual(1, stream.Read(m2, 1, 1)); Assert.AreEqual(2, await stream.ReadAsync(m2, 2, 2)); CollectionAssert.AreEqual(m1, m2); Assert.AreEqual(-1, stream.ReadByte()); Assert.IsFalse(stream.CanRead); }