def hash(buf, encoding="<STR_LIT:utf-8>"):
if isinstance(buf, six.text_type):<EOL><INDENT>buf = buf.encode(encoding)<EOL><DEDENT>if not isinstance(buf, six.binary_type):<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % type(buf)<EOL>)<EOL><DEDENT>result = ffi.new("<STR_LIT>", binding.lib.FUZZY_MAX_RESULT)<EOL>if binding.lib.fuzzy_hash_buf(buf, len(buf), result) != <NUM_LIT:0>:<EOL><INDENT>raise InternalError("<STR_LIT>")<EOL><DEDENT>return ffi.string(result).decode("<STR_LIT:ascii>")<EOL>
Compute the fuzzy hash of a buffer

:param String|Bytes buf: The data to be fuzzy hashed
:return: The fuzzy hash
:rtype: String
:raises InternalError: If lib returns an internal error
:raises TypeError: If buf is not String or Bytes