util.py
def compress(tree, uncompressed, compressed):
	'''First write the given tree to the stream 'compressed' using the
	write_tree function. Then use the same tree to encode the data
	from the input stream 'uncompressed' and write it to 'compressed'.
	If there are any partially-written bytes remaining at the end,
	write 0 bits to form a complete byte.

	Flush the bitwriter after writing the entire compressed file.

	Args:
	tree: A Huffman tree.
	uncompressed: A file stream from which you can read the input.
	compressed: A file stream that will receive the tree description
	and the coded input data.
	'''
	##let compressed be an instance of bitio.BitWriter
	Target = bitio.BitWriter(compressed)
	#let uncompressed be an instance of bitio.BitReader
	readingfile = bitio.BitReader(uncompressed)
	#Write the Huffman tree to compressed file.
	write_tree(tree, Target)

	#to get encoding table 
	encode = huffman.make_encoding_table(tree)
	while True:
		# try EOFError
		try:
			# can read a byte ?
			reading = readingfile.readbits(8)	
		except EOFError:
			# reach EOF encode eof,then get out of loop
			Target.writebit(0)
			Target.writebit(0)
			break
		#if no EOFError, get the sequence from tree using encoding table

		value = encode[reading]
		for v in value:
			# write v as a bit
			Target.writebit(v)

	Target.flush()
First write the given tree to the stream 'compressed' using the
	write_tree function. Then use the same tree to encode the data
	from the input stream 'uncompressed' and write it to 'compressed'.
	If there are any partially-written bytes remaining at the end,
	write 0 bits to form a complete byte.

	Flush the bitwriter after writing the entire compressed file.

	Args:
	tree: A Huffman tree.
	uncompressed: A file stream from which you can read the input.
	compressed: A file stream that will receive the tree description
	and the coded input data.
	
First write the given tree to the stream 'compressed' using the
write_tree function. Then use the same tree to encode the data
from the input stream 'uncompressed' and write it to 'compressed'.
If there are any partially-written bytes remaining at the end,
write 0 bits to form a complete byte.

Flush the bitwriter after writing the entire compressed file.

A Huffman tree.
uncompressed: A file stream from which you can read the input.
compressed: A file stream that will receive the tree description
and the coded input data.
First write the given tree to the stream ' compressed ' using the write_tree function . Then use the same tree to encode the data from the input stream ' uncompressed ' and write it to ' compressed ' . If there are any partially - written bytes remaining at the end write 0 bits to form a complete byte . Flush the bitwriter after writing the entire compressed file . A Huffman tree . uncompressed : A file stream from which you can read the input . compressed : A file stream that will receive the tree description and the coded input data .
def compress(tree, uncompressed, compressed):
	Target = bitio.BitWriter(compressed)
	readingfile = bitio.BitReader(uncompressed)
	write_tree(tree, Target)
	encode = huffman.make_encoding_table(tree)
	while True:
		try:
			reading = readingfile.readbits(8)	
		except EOFError:
			Target.writebit(0)
			Target.writebit(0)
			break
		value = encode[reading]
		for v in value:
			Target.writebit(v)
	Target.flush()
def compress ( tree , uncompressed , compressed ) : Target = bitio . BitWriter ( compressed ) readingfile = bitio . BitReader ( uncompressed ) write_tree ( tree , Target ) encode = huffman . make_encoding_table ( tree ) while True : try : reading = readingfile . readbits ( 8 ) except EOFError : Target . writebit ( 0 ) Target . writebit ( 0 ) break value = encode [ reading ] for v in value : Target . writebit ( v ) Target . flush ( )
First write the given tree to the stream 'compressed' using the
write_tree function.
First write the given tree to the stream ' compressed ' using the write_tree function .
'''First write the given tree to the stream 'compressed' using the
	write_tree function. Then use the same tree to encode the data
	from the input stream 'uncompressed' and write it to 'compressed'.
	If there are any partially-written bytes remaining at the end,
	write 0 bits to form a complete byte.

	Flush the bitwriter after writing the entire compressed file.

	Args:
	tree: A Huffman tree.
	uncompressed: A file stream from which you can read the input.
	compressed: A file stream that will receive the tree description
	and the coded input data.
	''' ##let compressed be an instance of bitio.BitWriter #let uncompressed be an instance of bitio.BitReader #Write the Huffman tree to compressed file. #to get encoding table  # try EOFError # can read a byte ? # reach EOF encode eof,then get out of loop #if no EOFError, get the sequence from tree using encoding table # write v as a bit
tree
uncompressed
compressed