Weird output on save string to file

Not sure what could be causing it, but when writing String to file, first half of the seems to be binary


I read an xml file remotely through ssh2 crate, all good at these stage

 let mut file_pointer: File = sftp_session.open_mode(xml_file_path.as_path(), (OpenFlags::READ | OpenFlags::WRITE), 700, OpenType::File).unwrap();

perform needed action, and updated the data

now i have the

 let serialized_data =  quick_xml::se::to_string(&current_firmware).unwrap();

I checked and confirmed the serialize string is correct


but on writing the string to file gives some weird output, only half the string is save the other half is garbage. below is the line i call

let hhh = file_pointer.write_all(serialized_data.as_bytes());

opening the file on text editor shows

It looks like you might be overwriting an existing longer file. How did you open the file to write to it? It would help to see more of the code.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.