added method streamToFile