public async Task TestReadAsync() { Size limitedSize = new Size(2); using (FileStream fileStream = readFileInfo.OpenRead()) using (LimitedStream limitedStream = new LimitedStream(fileStream, limitedSize)) { Assert.AreNotEqual(limitedSize.Bytes, fileStream.Length); Assert.AreEqual(limitedSize.Bytes, (await limitedStream.ReadToEndAsync()).LongLength); Assert.AreEqual(0, (await limitedStream.ReadToEndAsync()).LongLength); } }
public static async Task <byte[]> ReadMaxAsync(this Stream stream, Size limit, Size?estimatedSize = null) { using (LimitedStream limitedStream = new LimitedStream(stream, limit, leaveOpen: true)) { return(await limitedStream.ReadToEndAsync(estimatedSize)); } }