Function lib_rapid::compression::huffman::write_to_file [−][src]
pub fn write_to_file(path: String, bitvec: &BitVec, root: &Box<Node>)
Expand description
Writes the encoded message into 2 files.
Arguments
path
- The path to be written to.bitvec
- The Huffman codes assigned to the characters.root
- The Huffman tree.
Returns
Nothing. Writes to 2 files: name.hlr: The main file in which the encoded message is stored. name.htlr: The file in which the huffman tree is stored.
Examples
use lib_rapid::compression::huffman::{get_root, assign_codes, huffman_encode, huffman_decode, write_to_file}; use bit_vec::BitVec; use std::collections::HashMap; let s: &str = "Lorem Ipsum"; let root = get_root(s); let mut bitvec = BitVec::new(); let mut char_codes: HashMap<char, BitVec> = HashMap::new(); assign_codes(&root, &mut char_codes, &mut bitvec); // Assigns codes to characters of s and stores them in char_codes. let enc = huffman_encode(s, &mut char_codes); // Encodes the String s into enc. let dec = huffman_decode(&bitvec, &root); // Decodes the BitVec which was created by the last line. write_to_file("test".to_string(), &enc, &root);