From 3251523039e922378617af6f9850d749c77809c5 Mon Sep 17 00:00:00 2001 From: Dukantic Date: Sun, 13 Apr 2025 18:57:39 +0200 Subject: [PATCH] fix bin to string (read the doc) --- src/byte_writer.rs | 8 ++++---- src/read_and_write.rs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/byte_writer.rs b/src/byte_writer.rs index 3bf4803..7c2532f 100644 --- a/src/byte_writer.rs +++ b/src/byte_writer.rs @@ -41,13 +41,13 @@ pub fn binary_to_string(bytes: Vec, len: u32) -> String { } else { word.push('0'); } + n += 1; + if n >= len { + break; + } } binary = binary + &word; word = String::new(); - n += 1; - if n >= len { - break; - } } binary diff --git a/src/read_and_write.rs b/src/read_and_write.rs index 3658d09..432f787 100644 --- a/src/read_and_write.rs +++ b/src/read_and_write.rs @@ -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(())