JD2022-TU1/main/tools/framework/JD.Serializers/Stream/StreamExtensions.cs

25 lines
843 B
C#

namespace JD.Serializers.Stream
{
public static class StreamExtensions
{
/// <summary>
/// Appends the current stream to the destination stream.
/// </summary>
/// <remarks>
/// Copying starts from the current position in the source stream.
/// </remarks>
/// <param name="srcStream">Source stream.</param>
/// <param name="dstStream">Destination stream.</param>
public static void AppendTo(this System.IO.Stream srcStream, System.IO.Stream dstStream)
{
const int ChunkSize = 64 * 1024;
byte[] buffer = new byte[ChunkSize];
int bytesRead;
while ((bytesRead = srcStream.Read(buffer, 0, ChunkSize)) > 0)
{
dstStream.Write(buffer, 0, bytesRead);
}
}
}
}