chiark / gitweb /
Replace copy_to with direct use of the Read trait
authorSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 11:52:07 +0000 (11:52 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 11:52:07 +0000 (11:52 +0000)
src/main.rs

index cc81e6344889760beaaec38f08097387e354448e..f562a7404b301ac90e07256c47f5220a90115488 100644 (file)
@@ -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);
+    }
 }