Hmmm. Just purchased, so maybe I am missing something. I copied this code out of the StreamDemo project into a VS2010 console app:
FileStream sourceStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
FileStream destStream = new FileStream(fileName + ".zip", FileMode.Create, FileAccess.Write);
CompressedStream compStream = new CompressedStream(destStream, CompressionMethod.PPMd, CompressionLevel.Normal);
StreamCopy(compStream, destStream);
private static void StreamCopy(Stream sourceStream, Stream destStream)
{
try
{
int bytesRead;
byte[] buffer = new byte[32768];
while ((bytesRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
destStream.Write(buffer, 0, bytesRead);
}
finally
{
sourceStream.Close();
destStream.Close();
}
}
fileName is a valid XML file. I verified that the file stream is loading the file properly, and there is a zero-byte file being created for destination. However, this line: while ((bytesRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0) raises this error: This CompressedStream object does not support reading or decompressing.
What am I missing?