redesigned BinaryInputOutputStream API (passes regtests)