Many improvements to the stream I/O API.

Signed-off-by: Frank Mertens <frank@cyblogic.de>