If you’re still stuck on .NET 2.0, 3.0, or 3.5 for any reason and don’t have access to the
.CopyTo method for
System.IO.Stream objects, the
Stream.CopyTo extension method, available as a small NuGet package will make manually allocating buffers and other boilerplate associated with copying a buffer from one stream to another a thing of the past.
Stream.CopyTo is as simple as a NuGet package could be, but it let’s you use .NET 4.0’s
Stream.CopyTo method on earlier versions of the framework. It too resides in the
System.IO namespace and provides the same functions (and overrides) as the official .NET 4.0+ version of its namesake, meaning it’s a drop-in replacement perfect for publishing multi-targeted code, etc. that “just works” on all versions of the .NET Framework.
As with all our other NuGet publications,
Stream.CopyTo is fully open-source and published on GitHub under the terms of the MIT license. To make life easier, it’s also available on NuGet, making it a single Visual Studio package manager (console) install away.