title: Is it possible to use std::basic_ifstream and std::basic_ofstream with a custom buffer?
body: <p>I cannot figure out, is it possible to use std::basic_ifstream and std::basic_ofstream with a custom implementation of std::basic_filebuf?</p>
  
  <p>How complicated can be an implementation of an input file stream that reads the file by blocks of 64KB size and internally checks some hash value of the block? If the hash is not valid it throws corruption_exception, for example. The output file stream writes the block and the hash value after it.</p>
  
  <p>I found some examples that creates std::ifstream and then creates another stream that reads from it and does additional processing:</p>
  
  <pre><code>std::ifstream infile("test.img");
  decompress_stream in(infile, 288);
  char data[144 * 128];
  in.read(data, 144 * 128);
  infile.close();
  </code></pre>
  
  <p>But at first I expected it should be something like this (without an additional stream):</p>
  
  <pre><code>std::ifstrem in;
  in.setbuffer(new MyBuffer());
  in.read();
  
  MyBuffer::underflow()
  {
       //read from original buffer
       if (hash != calculated_sash) throw curruption_exception();
       //return the data with omitted hash.
  }
  </code></pre>
  
  <p>is this possible?</p>