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

About Streaming #23

Open
lazhenyi opened this issue Jan 3, 2025 · 2 comments
Open

About Streaming #23

lazhenyi opened this issue Jan 3, 2025 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@lazhenyi
Copy link

lazhenyi commented Jan 3, 2025

Hello, we are going to use your crate to build a distributed file system. Streaming is very important in this part, but I regret not seeing any relevant examples. I would be very happy if there were any. Thank you very much.

@surban
Copy link
Member

surban commented Jan 3, 2025

Could you specify what kind of streaming example you would like?

@surban surban added the documentation Improvements or additions to documentation label Jan 3, 2025
@lazhenyi
Copy link
Author

lazhenyi commented Jan 3, 2025

Could you specify what kind of streaming example you would like?

refer to

   let mut cmd = Command::new("**");
   cmd.stdout(Stdio::piped());
    let mut process = match cmd.spawn() {
          Ok(process) => process,
          Err(e) => {
              info!("Error running command: {}", e);
              return Err(anyhow::anyhow!("Error running command"));
          }
      };
   let mut stdout = process.stdout.take().unwrap();


   let stream:AsyncStream<Result<bytes::Bytes, io::Error>, impl Future<Output=()>+Sized> = stream! {
            let mut buffer = [0; 8192];
            loop {
                match stdout.read(&mut buffer) {
                    Ok(0) => break, // EOF
                    Ok(n) => yield Ok::<_, io::Error>(bytes::Bytes::copy_from_slice(&buffer[..n])),
                    Err(e) => {
                        eprintln!("Error reading stdout: {}", e);
                        break;
                    }
                }
            }
        };

At this time, I want to use stream as the transmission content. How should I operate here? I am confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants