This is the key:
https://msdn.microsoft.com/en-us/library/system.io.stream.seek%28v=vs.110%29.aspx[
^].
Steams, by definition, are read from the beginning to the end. So, to invert bits, you need to read the stream (returning true from
CanSeek
. which is the case if you work with files, as in your example) in chunks an invert each chunk in memory. If the stream is small enough, it's not a problem to do it all in memory. For big streams, you have to to it all chunk by chunk. So, you have to read the stream size and plan the sizes and addresses of all chunks, and the read from the last to chunk to the first one. The inverted chunks can be written to the output stream immediately. This is pretty simple. I hope you don't need help in inverting chunks in memory.
—SA