pub fn binary_to_ascii(
binary: &[u8],
with_block_comments: bool,
) -> Result<Box<str>, BinaryGcodeError>Expand description
Provide a reference to a u8 slice of the entire binary file you would like to decode.
Examples found in repository?
examples/read_file.rs (line 12)
5fn main() {
6 // Create the path to the gcode file
7 let mut path = env::current_dir().unwrap();
8 path.push("test_files");
9 path.push("mini_cube_b.bgcode");
10
11 let binary = fs::read(path).unwrap();
12 let gcode = binary_to_ascii(&binary, true).unwrap();
13 println!(
14 "Binary Length: {}, ASCII Lenght: {}",
15 binary.len(),
16 gcode.len()
17 );
18
19 fs::write("tmp/ascii.gcode", gcode.as_ref()).unwrap();
20}More examples
examples/serde_file.rs (line 18)
5fn main() {
6 // Create the path to the gcode file
7 let mut path = env::current_dir().unwrap();
8 path.push("test_files");
9 path.push("mini_cube_b.gcode");
10
11 // Read the data into memory
12 let before = fs::read_to_string(path).unwrap();
13 println!("Before: {}", before.len());
14 // Convert to binary
15 let binary = ascii_to_binary(&before).unwrap();
16 println!("Binary: {}", binary.len());
17 // Convert back to str
18 let after = binary_to_ascii(&binary, true).unwrap();
19 println!("After: {}", after.len());
20
21 // Lets see what we get
22 fs::write("tmp/serde.gcode", after.as_ref()).unwrap();
23}