Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - The file.log upload to ftp server. then lost \n line breaks #79

Open
EternalNight996 opened this issue Mar 28, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@EternalNight996
Copy link

The Upload code of Core

fn test() {
  let mut buffer = Vec::new();
  let mut f = fs::File::open(src).unwrap();
  let mut reader = f
    .read_to_end(&mut buffer)
    .map(|_| Cursor::new(buffer))
    .map_err(FtpError::ConnectionError)?;
  match upload_type {
    StorageUploadType::Append => {
      ftp.append_file(&fname, &mut reader)?;
    }
    StorageUploadType::Replace => {
      ftp.put_file(&fname, &mut reader)?;
    }
    StorageUploadType::Once => {
      if ftp.size(&fname).is_err() {
        ftp.put_file(&fname, &mut reader)?;
      } else {
        /* 已经存在 */
      }
    }
  };
}
@EternalNight996 EternalNight996 added the bug Something isn't working label Mar 28, 2024
@EternalNight996
Copy link
Author

I have found the problem, but please do not handle line breaks on different platforms;
Adding the following code solves this problem;
So I have the following proposal: for FPT uploads, we can increase the recognition of the FTP server platform;
Then process the data;
Secondly, increase the judgment of file types and only handle text types;

Let mut buffer=Vec:: new();
Let mut f=fs:: File:: open (src). unwrap();
Let mut reader=f
. readuto_end (&mut buffer)
. map (| _ |{
//Iterate over multiple references to each byte and replace '\ n' with '\ n'
//Use map to replace '\ n' with '\ n' and collect into a new Vec<u8>
Let modified_data: Vec<u8>=buffer
. iter()
. map (|&byte |{
If byte==b '\ n'{
Vec! [b '\ r', b '\ n']
}Else{
Vec! [byte]
}
})
. flatten()
. collect();

Cursor:: new (modified_data)
})
. map_err (FtpError: ConnectionError)?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants