Function lib_rapid::compression::huffman::read_from_file [−][src]
pub fn read_from_file(path: String) -> String
Expand description
Reads and decodes the message stored in the .hlr and .htlr files.
Arguments
path
- The path to be read from.
Returns
A String containing the decoded message.
Examples
use lib_rapid::compression::huffman::{get_root, assign_codes, huffman_encode, huffman_decode, write_to_file, read_from_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); let dec_written = read_from_file("test".to_string());