etf.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Pyrlang 作者: esl 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号