public void ReadsExpectedBytes(int position) { // Arrange var bufferA = Encoding.ASCII.GetBytes("0"); var bufferB = Encoding.ASCII.GetBytes("12"); var bufferC = Encoding.ASCII.GetBytes("345"); var bufferD = Encoding.ASCII.GetBytes("6789"); var bufferE = Encoding.ASCII.GetBytes("ABCDE"); var target = new BlockMemoryStream(); target.Append(bufferC); target.Prepend(bufferB); target.Append(bufferD); target.Append(bufferE); target.Prepend(bufferA); var expected = "0123456789ABCDE" + new string('_', (int)target.Length); expected = expected.Substring(position); var buffer = Encoding.ASCII.GetBytes(new string('_', expected.Length)); target.Position = position; // Act var read = target.Read(buffer, 0, buffer.Length); // Assert var actual = Encoding.ASCII.GetString(buffer); Assert.Equal(expected, actual); Assert.Equal(Math.Max(0, target.Length - position), read); }
/// <summary> /// Initializes an instance of a buffered range reader stream. /// </summary> /// <param name="rangeReader">The interface used for reading ranges of bytes.</param> /// <param name="length">The total length of the file reader by <paramref name="rangeReader"/>.</param> /// <param name="bufferSizeProvider">The interface used to determine what buffer sizes to use.</param> public BufferedRangeStream(IRangeReader rangeReader, long length, IBufferSizeProvider bufferSizeProvider) : base(length) { _rangeReader = rangeReader; _bufferSizeProvider = bufferSizeProvider; _buffer = new BlockMemoryStream(); BufferPosition = length; }