Module: Huffman::BinaryStream

Extended by:
BinaryStream
Included in:
BinaryStream
Defined in:
lib/huffman/binary_stream.rb

Instance Method Summary collapse

Instance Method Details

#get_bits_from_text(txt, dictionnary) ⇒ Object


5
6
7
8
# File 'lib/huffman/binary_stream.rb', line 5

def get_bits_from_text(txt,dictionnary)
	dictionnary = dictionnary.invert
	txt.each_char.map{|char|  ; dictionnary[char]}.join
end

#get_text_from_bits(bits, dictionnary) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/huffman/binary_stream.rb', line 10

def get_text_from_bits(bits,dictionnary)
	original_text = '' ; buffer = ''
	bits.each_char do |bit| 
		buffer += bit
		# Si il y'a une correspondance
		if dictionnary[buffer] 
			 # Si c'est le marqueur de fin EOF 
		     return original_text if dictionnary[buffer] == EOT
		    
			 original_text += dictionnary[buffer] 
			 buffer.clear
		end
	end
	original_text
end