added support to read from a StringIO or an already opened file