LZW解压缩算法——python版

1964天前 · python · 997次阅读

def uncompress(compressed):
    k = compressed
    n = [[_] for _ in range(256)]
    q = 0
    t = 0
    Ea = 8
    H = [0 for _ in range(ceil(1.5 * len(k)))]
    K = 0
    L = []
    while (q < len(k) and 8 * (len(k) - q) - t > Ea):
        S = 0
        A = 0
        while (S < Ea):
            J = min(Ea - S, 8 - t)
            B = (k[q] << t & 255) >> 8 - J
            S = S + J
            t = t + J
            if 8 == t:
                t = 0
                q += 1
            A |= (B & 255) << Ea - S
        S = [] if A >= len(n) else n[A]
        if 0 == len(L):
            Ea += 1
        else:
            L.append(S[0]) if S else L.append(L[0])
            n.append(L)
            L = []
            if len(n) == 1 << Ea:
                Ea += 1
            S = n[A]
        A = K + len(S)
        if A >= len(H):
            J = [0 for _ in  range(ceil(1.5 * A))]
            J[:len(H)] = H
            H = J
        H[K:K+len(S)]=S
        K = A
        L += S
    return bytes(H[:K]).decode("utf-8")
👍 3

Netflix

最后修改于1928天前

评论

贴吧 狗头 原神 小黄脸
收起

贴吧

狗头

原神

小黄脸

目录

avatar

未末

迷失

126

文章数

275

评论数

7

分类