Replaced catch() with check for unknown stream length

... as requested by @haraldk. I only changed a few lines. No idea why the diff looks this crazy.