This project is read-only.

TotalOut of DeflateStream returns bad value

Nov 3, 2010 at 3:08 PM


I have the following piece of code:

byte[] buffer = new byte[16384];
int bytesRead;
uint totalRead = 0;
Stream outStream;

long posStart = this.ZipFileStream.Position;
long sourceStart = _source.Position;

DeflateStream outStream = new DeflateStream(_destination, CompressionMode.Compress, CompressionLevel.BestCompression);

	bytesRead = _source.Read(buffer, 0, buffer.Length);
	totalRead += (uint)bytesRead;
	if (bytesRead > 0)
		outStream.Write(buffer, 0, bytesRead);
} while (bytesRead == buffer.Length);

long compressedSize = outStream.TotalOut;

In this piece of code I want to compress a given (_source) stream into an output (_destination) stream. Afterwards I want to see how many bytes have been written into the destination stream by using the TotalOut property. But this property often returns 0 or another number which not the total size of the compressed data...
What am I missing or doing wrong?