// Grab the file contents, which were encoded/decoded automatically
// into python"s format
decoded_string = raw_bytes.decode(encoding_type)
return decoded_string.replace("\x00", "")
After Change
bom16_le = str(codecs.BOM_UTF16_LE)
bom16_be = str(codecs.BOM_UTF16_BE)
if str(raw_bytes).startswith(bom16_le):
decoded_string = raw_bytes[len(bom16_le):-1]decoded_string = decoded_string.replace("b"", "")decoded_string = decoded_string.replace("\\x00", "")
elif str(raw_bytes).startswith(bom16_be):
decoded_string = raw_bytes[len(bom16_be):-1]
decoded_string = decoded_string.replace("b"", "")
decoded_string = decoded_string.replace("\\x00", "")
else:
try:
// try to use utf-8 to decode first
encoding_type = "utf-8"
// Grab the file contents, which were encoded/decoded automatically
// into python"s format
decoded_string = raw_bytes.decode(encoding_type)
except UnicodeDecodeError:
encoding_detect = chardet.detect(
raw_bytes[:constants.MIN_ENCODING_DETECT]) // Detect the encoding
encoding_type = encoding_detect["encoding"]
// Grab the file contents, which were encoded/decoded automatically
// into python"s format
decoded_string = raw_bytes.decode(encoding_type)
return decoded_string