DRY error checks a little bit
add isDefined to util
decouple read-stream from encoding and opening stuff