def view(self, fileName): if not os.path.exists(fileName): print('File doesnt exist.') return readFile = BitStream(fileName, 'rb') for i in range(100): c = readFile.read(8) if not c: break print(c) readFile.close()
def decodeFile(self, fileName, outFileName): if not os.path.exists(fileName): print('File doesnt exist.') return readFile = BitStream(fileName, 'rb') writeFile = open(outFileName, 'wb') self.tree.counter = int(readFile.read(32), 2) while True: char = self.tree.decode(readFile) if not char: break writeFile.write(char) # writeFile.flush() # self.tree.printTree() readFile.close() writeFile.close()
def encodeFile(self, fileName, outFileName): if not os.path.exists(fileName): print('File doesnt exist.') return readFile = open(fileName, 'rb') writeFile = BitStream(outFileName, 'wb') # the size of file writeFile.write('{0:032b}'.format(os.stat(fileName).st_size)) while True: code = self.tree.encode(readFile) if not code: break writeFile.write(code) self.tree.printTree() readFile.close() writeFile.close()