def encode(self, infile, outfile): s='' chars=[] print(BitArray(filename=infile).bin[2:]) f=ConstBitStream(filename=infile) done=False eof=False while not done: found=False cursor=self.encoding while not found: try: bit=f.read('uint:1') except: eof=True bit=0 cursor=cursor[bit+1] if len(cursor)==2: # leaf found=True val=cursor[1] s=s+chr(val) chars.append(val) if eof: done=True f=open(outfile, 'wb') f.write(s) f.close() print(chars) print(BitArray(filename=outfile).bin[2:])
def encode(self, infile, outfile): s = '' chars = [] print(BitArray(filename=infile).bin[2:]) f = ConstBitStream(filename=infile) done = False eof = False while not done: found = False cursor = self.encoding while not found: try: bit = f.read('uint:1') except: eof = True bit = 0 cursor = cursor[bit + 1] if len(cursor) == 2: # leaf found = True val = cursor[1] s = s + chr(val) chars.append(val) if eof: done = True f = open(outfile, 'wb') f.write(s) f.close() print(chars) print(BitArray(filename=outfile).bin[2:])