code: def _read_stream_as_string(stream, encoding):
      
      output = io.BytesIO()
      try:
          for data in stream:
              output.write(data)
          if encoding is None:
              encoding = 'utf-8'
          return output.getvalue().decode(encoding)
      finally:
          output.close()
      raise RuntimeError('could not write data to stream or decode bytes')
docs: Read stream as string
      Originally in azure-batch-samples.Python.Batch.common.helpers
  
      :param stream: input stream generator
      :param str encoding: The encoding of the file. The default is utf-8.
      :return: The file content.
      :rtype: str