code: def get_chardet_encoding(binary_contents: bytes) -> Optional[str]:
      
      if not binary_contents:
          return None
      if chardet is None or UniversalDetector is None:
          log.warning("chardet not installed; limits detection of encodings")
          return None
      # METHOD 1
      # http://chardet.readthedocs.io/en/latest/
      #
      # guess = chardet.detect(binary_contents)
      #
      # METHOD 2: faster with large files
      # http://chardet.readthedocs.io/en/latest/
      # http://stackoverflow.com/questions/13857856/split-byte-string-into-lines
  
      # noinspection PyCallingNonCallable
      detector = UniversalDetector()
      for byte_line in binary_contents.split(b"\n"):
          detector.feed(byte_line)
          if detector.done:
              break
      guess = detector.result
      # Handle result
      if 'encoding' not in guess:
          log.warning("Something went wrong within chardet; no encoding")
          return None
      return guess['encoding']
docs: Guess the character set encoding of the specified ``binary_contents``.