Pass the Stream into the constructor of a StreamReader, then buffer the input (in blocks, for which 4096 is a good size typically) to a TextWriter derivative (perhaps a StreamWriter with a FileStream passed to its constructor that points at the right place. This will also allow you to change the encoding if you like. You could skip the readers and writers, though, and just buffer the input directly from the Stream to a FileStream, something like:
private void Save(Stream s)
{
FileStream file = new FileStream("c:\temp\file.txt", ...);
using (file)
{
byte[] buffer = new byte[4096];
int read = 0;
read = s.Read(buffer, 0, buffer.Length);
while (read != 0)
{
file.Write(buffer, 0, read);
read = s.Read(buffer, 0, buffer.Length);
}
}
}
A very simplistic example, but you should get the idea. The code would be similar using a TextReader and TextWriter derivative, but would allow you to more easily handle text as opposed to binary data (although you could still get an encoded string at any time using the Encoding class derivatives).
Microsoft MVP, Visual C# My Articles