title: Streams implementation in C#
body: <p><em>What do I have to do to implement my own stream, <strong>which uses custom compression routine</strong>, similiar to, for example, <a href="http://msdn.microsoft.com/ru-ru/library/system.io.compression.gzipstream.aspx" rel="nofollow noreferrer"><code>GZipStream</code></a>?</em></p>
  <p>I obviously have to subclass the <code>Stream</code> class, but which methods should be implemented by me and which methods can be left with their default implementations?</p>
  <p>Basically speaking, there is a special part of documentation, <strong>but maybe there is a better and easier option?</strong></p>
  <blockquote>
  <p>Notes to Implementers</p>
  <p>When implementing a derived class of Stream, you
  must provide implementations for the Read and Write methods. The
  asynchronous methods BeginRead, EndRead, BeginWrite, and EndWrite are
  implemented through the synchronous methods Read and Write. Similarly,
  your implementations of Read and Write will work correctly with the
  asynchronous methods. The default implementations of ReadByte and
  WriteByte create a new single-element byte array, and then call your
  implementations of Read and Write. When deriving from Stream, if you
  have an internal byte buffer, it is strongly recommended that you
  override these methods to access your internal buffer for
  substantially better performance. You must also provide
  implementations of CanRead, CanSeek, CanWrite, Flush, Length,
  Position, Seek, and SetLength.</p>
  <p>Do not override the Close method, instead, put all of the Stream
  cleanup logic in the Dispose method. For more information, see
  Implementing a Dispose Method.</p>
  </blockquote>