It’s kinda odd - but there’s no standard way to copy between streams in the .net framework. Coming from a Delphi background, I’m used to being able to easily copy information from one stream to another easily.

Why? The common ancestor to all Delphi streams (TStream) includes a method that does exactly that. Here is the declaration:

function CopyFrom(Source: TStream; Count: Int64): Int64;

This allows you to copy a specified number of bytes from the current position in one stream into a target stream.

The .Net framework doesn’t have this - meaning that whenever there is a need to copy information from one stream to another (a common enough occurrence), the developer needs to roll their own.

Admittedly, the function is easy enough to implement (there is even an example buried in the help file, if you can but find it).

It just seems an oddly fundamental thing to have left out - isn’t the whole idea of a framework to supply the common stuff so you can concentrate on the things unique to your application?

Update April 2014: It took several years, but in .NET 4.0 Microsoft introduced a CopyTo method on the Stream base class. Yay!

Comments

blog comments powered by Disqus
Next Post
Wiki for the win  01 Dec 2003
Prior Post
Exceptions and Resources  03 Dec 1998
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
Archives
November 2003
2003