make urlToFile and streamToFile more flexible