To implement a new stream buffer, we derive a single class from streambuf. The stream classes are trivial really. The real work happens here.

OK, this is all very well, but why the hell would I want to write a new stream buffer in the first place?