def binary_to_term(data: bytes, options: dict = {}):
""" Strip 131 header and unpack if the data was compressed.
:param data: The incoming encoded data with the 131 byte
:param options: See description on top of the module
:raises ETFDecodeException: when the tag is not 131, when compressed
data is incomplete or corrupted
"""
if data[0] != ETF_VERSION_TAG:
raise ETFDecodeException("Unsupported external term version")
if data[1] == TAG_COMPRESSED:
do = decompressobj()
decomp_size = util.u32(data, 2)
decomp = do.decompress(data[6:]) + do.flush()
if len(decomp) != decomp_size:
# Data corruption?
raise ETFDecodeException("Compressed size mismatch with actual")
return binary_to_term_2(decomp, options)
return binary_to_term_2(data[1:], options)
评论列表
文章目录