Fixed error when parsing a stream from memory

Previous version mistakenly treats all streams as file objects, but in
real life usage, that might not be true.