private static byte[] Peek(RingBufferStream stream) { var buffer = new byte[stream.Length - stream.Position]; stream.Peek(buffer, 0, buffer.Length); return(buffer); }
public void TestPeek() { // 16 cap var ringBuffer = new RingBufferStream(12); var buffer = new byte[] { 1, 2, 3, 4, 5 }; ringBuffer.Write(buffer, 0, buffer.Length); Assert.AreEqual(11, ringBuffer.WriteableCount); Assert.AreEqual(5, ringBuffer.ReadableCount); CollectionAssert.AreEqual( new byte[] { 1, 2, 3, 4, 5, }, Peek(ringBuffer)); var actual = new byte[5]; var read = ringBuffer.Peek(actual, 3, actual.Length - 3); Assert.AreEqual(2, read); CollectionAssert.AreEqual( new byte[] { 0, 0, 0, 1, 2, }, actual); read = ringBuffer.Peek(actual, 0, actual.Length); Assert.AreEqual(5, read); CollectionAssert.AreEqual( new byte[] { 1, 2, 3, 4, 5, }, actual); Assert.AreEqual(11, ringBuffer.WriteableCount); Assert.AreEqual(5, ringBuffer.ReadableCount); Read(ringBuffer); Assert.AreEqual(16, ringBuffer.WriteableCount); Assert.AreEqual(0, ringBuffer.ReadableCount); }