lib: use stream state instead of eof() to determine end of stream