fix bin to string (read the doc)
This commit is contained in:
@@ -41,14 +41,14 @@ pub fn binary_to_string(bytes: Vec<u8>, len: u32) -> String {
|
||||
} else {
|
||||
word.push('0');
|
||||
}
|
||||
}
|
||||
binary = binary + &word;
|
||||
word = String::new();
|
||||
n += 1;
|
||||
if n >= len {
|
||||
break;
|
||||
}
|
||||
}
|
||||
binary = binary + &word;
|
||||
word = String::new();
|
||||
}
|
||||
|
||||
binary
|
||||
}
|
||||
|
||||
@@ -44,9 +44,13 @@ pub fn save_action(txt: &str, file: &mut File) -> Result<(), std::io::Error> {
|
||||
file.write_all(string.as_bytes())?;
|
||||
|
||||
let map = tree_to_map(&mut tree, true);
|
||||
eprintln!("&txt = {:?}", &txt);
|
||||
let trad = body_to_bin(&txt, map);
|
||||
eprintln!("trad = {:?}", trad);
|
||||
let trad_bin = string_to_binary(&trad);
|
||||
eprintln!("trad_bin = {:?}", trad_bin);
|
||||
let len_body = trad.len() as u32;
|
||||
eprintln!("len_body = {:?}", len_body);
|
||||
file.write_all(&len_body.to_be_bytes())?;
|
||||
file.write_all(&trad_bin)?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user