compression-identifier.py 文件源码

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

项目:compression-identifier 作者: koutto 项目源码 文件源码
def compress_zlib(data):
    compressed = None
    zlib_compress = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS)
    try:
        compressed = zlib_compress.compress(data) + zlib_compress.flush()
    except Exception as e:
        print_error('Error when compressing with Zlib: {0}'.format(e))
    return compressed

# def decompress_zlib(data):
#     decompressed = None
#     i = -15

#     # The absolute value of wbits is the base two logarithm of the size of the history buffer (the "window size") 
#     # used when compressing data
#     valid_wbits = []
#     truncated_wbits = []
#     decompressed = None

#     for i in range(-15,16):
#         try:
#             decompressed = zlib.decompress(data, i)
#             valid_wbits.append(i)
#         except zlib.error as e:
#           # Error -5 : incomplete or truncated data input implies that it's zlib compressed but the stream is not complete
#           if str(e).startswith('Error -5'):
#               tuncated_wbits.append(i) 
#   return (valid_wbits, truncated_wbits, decompressed)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号