Convert _stream_response_to_file to a utility function