System.IO.StreamExtensions.CopyTo C# (CSharp) Method

CopyTo() public static method

public static CopyTo ( this source, Stream destination, long start, long length, Action chunkAction ) : void
source this
destination Stream
start long
length long
chunkAction Action
return void
		public static void CopyTo(this Stream source, Stream destination, long start, long length, Action chunkAction)
		{
			var end = start + length;
			source.Seek(start, SeekOrigin.Begin);
			var bytesRemaining = end - source.Position;
			var buffer = new byte[ReadStreamBufferSize];

			while (bytesRemaining > 0)
			{
				var bytesRead = source.Read(buffer, 0, bytesRemaining > ReadStreamBufferSize ? ReadStreamBufferSize : (int) bytesRemaining);

				if (bytesRead == 0)
					break;

				destination.Write(buffer, 0, bytesRead);
				chunkAction();

				bytesRemaining = end - source.Position;
			}
		}

Same methods

StreamExtensions::CopyTo ( this source, Stream destination ) : void