def decode(fin, fout, size): rp = 0 buff = [0] * (1 << POS_BITS) while size > 0: if fin.getbit() == 1: num = fin.getbits(LEN_BITS) + MIN_LEN pos = rp - (fin.getbits(POS_BITS) + 1) if pos < 0: pos += len(buff) for _ in xrange(num): c = buff[pos] BitIO.putc(fout, c) buff[rp] = c pos += 1 rp += 1 if pos >= len(buff): pos = 0 if rp >= len(buff): rp = 0 else: num = 1 c = fin.getbits(8) BitIO.putc(fout, c) buff[rp] = c rp += 1 if rp >= len(buff): rp = 0 size -= num
def fread(self, start, size): # データ入力 for i in xrange(size): c = BitIO.getc(self.file) if c is None: return i self.buff[start + i] = c return size