Matroska-Solution / Matroska / NEbml / Core / StreamExtensions.cs
Code · 21 lines · 447 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21using System.IO;

namespace NEbml.Core
{
	public static class StreamExtensions
	{
		public static int ReadFully(this Stream stream, byte[] buffer, int offset, int count)
		{
			int bytesRead = 0;
			int totalBytesRead = 0;

			do
			{
				bytesRead = stream.Read(buffer, offset + totalBytesRead, count - totalBytesRead);
				totalBytesRead += bytesRead;
			} while (bytesRead > 0 && totalBytesRead < count);

			return totalBytesRead;
		}
	}
}