Search code examples
.net.net-4.0streamdeflatestream

What does the Flush method do on a DeflateStream?


What does the Flush method do on a DeflateStream?

The description for the DeflateStream.Flush method is:

Flushes the contents of the internal buffer of the current stream object to the underlying stream.

Is this an accurate description? And if so, what does it mean?

To elaborate on the points of confusion: The DeflateStream constructor requires a Stream argument described as "The stream to compress or decompress". Is that "the underlying stream"? If so, why would you flush a buffer to the stream you're compressing or decompressing? If not, then what is "the underlying stream"?


Solution

  • If you look at the documentation,

    The current implementation of this method has no functionality.

    Remarks

    The current implementation of this method does not flush the internal buffer. The internal buffer is flushed when the object is disposed.

    It's there because it has to be there. It comes from the polymorphic parent Stream, where, as I suspect you already know, it's useful for most other kinds of streams, like NetworkStream and FileStream.