fix up StreamBuf, add unit tests for it