From: Simon Tatham Date: Sat, 23 Dec 2023 11:52:07 +0000 (+0000) Subject: Replace copy_to with direct use of the Read trait X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=a8d89f566285733167bc0ee5ab0d48382639a350;p=mastodonochrome.git Replace copy_to with direct use of the Read trait --- diff --git a/src/main.rs b/src/main.rs index cc81e63..f562a74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,22 @@ // use mastodonochrome::types::*; +use std::io::Read; fn main() { let auth = std::fs::read_to_string( "/home/simon/.config/mastodonochrome/auth").unwrap(); - dbg!(&auth); let auth: serde_json::Value = serde_json::from_str(&auth).unwrap(); - dbg!(&auth); let auth = &auth["user_token"].as_str().unwrap(); - dbg!(&auth); let client = reqwest::blocking::Client::new(); let mut req = client.get( "https://hachyderm.io/api/v1/streaming/user") .bearer_auth(auth) .send().unwrap(); - req.copy_to(&mut std::io::stdout()); + + const BUFSIZE: usize = 4096; + let mut buf: [u8; BUFSIZE] = [0; BUFSIZE]; + while let Ok(sz) = req.read(&mut buf) { + let read = &buf[..sz]; + dbg!(read); + } }