I have never tried doing it this way, but it looks like you took the sample from here[^], removed some stuff to make it simpler and changed it to write directly to your generic IStream object. I am not sure I like the whole thing, but it is kind of an interesting approach - if it works.
You do not show how you acquire the data that is stored in chIncomingDataBuffer. Are you sure this buffer contains an entire image?
I don't know if it is going to work, but right after you write the data to your pstream, its internal position will be pointing to the end of the data you just wrote. Try calling Seek() in order to change it to point to the start of the data.
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty