Example #1
0
def run_compressor (filename):
    with open(filename, 'rb') as uncompressed:
        freqs = huffman.make_freq_table(uncompressed)
        tree = huffman.make_tree(freqs)
        uncompressed.seek(0)
        with open(filename+'.huf', 'wb') as compressed:
            util.compress(tree, uncompressed, compressed)
def run_compressor (filename):
    with open(filename, 'rb') as uncompressed:
        freqs = huffman.make_freq_table(uncompressed)
        tree = huffman.make_tree(freqs)
        uncompressed.seek(0)
        with open(filename+'.huf', 'wb') as compressed:
                util.compress(tree, uncompressed, compressed)
Example #3
0
def huffman(infile):
    with open(infile, 'rb') as uncompressed:
        freqs = make_freq_table(uncompressed)
        tree = make_tree(freqs)
        uncompressed.seek(0)
        with open(infile + '.huf', 'wb') as compressed:
            util.compress(tree, uncompressed, compressed)
Example #4
0
def read_tree (bitreader):
    '''Read a description of a Huffman tree from the given bit reader,
    and construct and return the tree. When this function returns, the
    bit reader should be ready to read the next bit immediately
    following the tree description.

    Huffman trees are stored in the following format:
      * TreeLeafEndMessage is represented by the two bits 00.
      * TreeLeaf is represented by the two bits 01, followed by 8 bits
          for the symbol at that leaf.
      * TreeBranch is represented by the single bit 1, followed by a
          description of the left subtree and then the right subtree.

    Args:
      bitreader: An instance of bitio.BitReader to read the tree from.

    Returns:
      A Huffman tree constructed according to the given description.
    '''
    #pass

    freqs_table = huffman.make_freq_table(bitreader)
    tree = huffman.make_tree(freq_table)

    return tree
def run_compressor(filename):
    # opening file to read
    with open(filename, 'rb') as uncompressed:
        # makefreqtable reads the whole file
        freqs = huffman.make_freq_table(uncompressed)
        tree = huffman.make_tree(freqs)
        # reinitializing the file 'editing cursor' back to
        # the start of the file
        uncompressed.seek(0)
        with open(filename + '.huf', 'wb') as compressed:
            # adding tree_stream as a parameter...????????
            util.compress(tree, uncompressed, compressed)