import logging


def ByteStreamCopyToString(byte_stream, codepage='utf-8'):
  """Copies a UTF-8 encoded byte stream into a Unicode string.

  Args:
    byte_stream: A byte stream containing an UTF-8 encoded string.
    codepage: The codepage of the byte stream.

  Returns:
    A Unicode string.
  """
  try:
    string = byte_stream.decode(codepage)
  except UnicodeDecodeError:
    logging.warning(
        'Unable to decode {0:s} formatted byte stream.'.format(codepage))
    string = byte_stream.decode(codepage, errors='ignore')

  string, _, _ = string.partition('\x00')
  return string