Properly handle null and stream files