code: def decode_terminated(data, encoding, strict=True):
      
  
      codec_info = codecs.lookup(encoding)
  
      # normalize encoding name so we can compare by name
      encoding = codec_info.name
  
      # fast path
      if encoding in ("utf-8", "iso8859-1"):
          index = data.find(b"\x00")
          if index == -1:
              # make sure we raise UnicodeError first, like in the slow path
              res = data.decode(encoding), b""
              if strict:
                  raise ValueError("not null terminated")
              else:
                  return res
          return data[:index].decode(encoding), data[index + 1:]
  
      # slow path
      decoder = codec_info.incrementaldecoder()
      r = []
      for i, b in enumerate(iterbytes(data)):
          c = decoder.decode(b)
          if c == u"\x00":
              return u"".join(r), data[i + 1:]
          r.append(c)
      else:
          # make sure the decoder is finished
          r.append(decoder.decode(b"", True))
          if strict:
              raise ValueError("not null terminated")
          return u"".join(r), b""
docs: Returns the decoded data until the first NULL terminator
      and all data after it.
  
      Args:
          data (bytes): data to decode
          encoding (str): The codec to use
          strict (bool): If True will raise ValueError in case no NULL is found
              but the available data decoded successfully.
      Returns:
          Tuple[`text`, `bytes`]: A tuple containing the decoded text and the
              remaining data after the found NULL termination.
  
      Raises:
          UnicodeError: In case the data can't be decoded.
          LookupError:In case the encoding is not found.
          ValueError: In case the data isn't null terminated (even if it is
              encoded correctly) except if strict is False, then the decoded
              string will be returned anyway.