{"id":13439138,"url":"https://github.com/pop-os/progress-streams","last_synced_at":"2025-04-30T23:32:23.828Z","repository":{"id":62442973,"uuid":"152302753","full_name":"pop-os/progress-streams","owner":"pop-os","description":"Rust crate to extend io::Read \u0026 io::Write types with progress callbacks","archived":false,"fork":false,"pushed_at":"2019-07-25T17:29:07.000Z","size":5,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-28T01:11:53.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pop-os.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-09T18:40:05.000Z","updated_at":"2024-08-28T22:54:26.000Z","dependencies_parsed_at":"2022-11-01T22:16:33.649Z","dependency_job_id":null,"html_url":"https://github.com/pop-os/progress-streams","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pop-os%2Fprogress-streams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pop-os%2Fprogress-streams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pop-os%2Fprogress-streams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pop-os%2Fprogress-streams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pop-os","download_url":"https://codeload.github.com/pop-os/progress-streams/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224225370,"owners_count":17276501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:11.468Z","updated_at":"2024-11-12T06:17:52.760Z","avatar_url":"https://github.com/pop-os.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries","库"],"sub_categories":["Data structures","数据结构 Data structures","数据结构"],"readme":"# progress-streams\n\nRust crate to provide progress callbacks for types which implement `io::Read` or `io::Write`.\n\n## Examples\n\n### Reader\n\n```rust\nextern crate progress_streams;\n\nuse progress_streams::ProgressReader;\nuse std::fs::File;\nuse std::io::Read;\nuse std::sync::Arc;\nuse std::sync::atomic::{AtomicUsize, Ordering};\nuse std::thread;\nuse std::time::Duration;\n\nfn main() {\n    let total = Arc::new(AtomicUsize::new(0));\n    let mut file = File::open(\"/dev/urandom\").unwrap();\n    let mut reader = ProgressReader::new(\u0026mut file, |progress: usize| {\n        total.fetch_add(progress, Ordering::SeqCst);\n    });\n\n    {\n        let total = total.clone();\n        thread::spawn(move || {\n            loop {\n                println!(\"Read {} KiB\", total.load(Ordering::SeqCst) / 1024);\n                thread::sleep(Duration::from_millis(16));\n            }\n        });\n    }\n\n    let mut buffer = [0u8; 8192];\n    while total.load(Ordering::SeqCst) \u003c 100 * 1024 * 1024 {\n        reader.read(\u0026mut buffer).unwrap();\n    }\n}\n```\n\n### Writer\n\n```rust\nextern crate progress_streams;\n\nuse progress_streams::ProgressWriter;\nuse std::io::{Cursor, Write};\nuse std::sync::Arc;\nuse std::sync::atomic::{AtomicUsize, Ordering};\nuse std::thread;\nuse std::time::Duration;\n\nfn main() {\n    let total = Arc::new(AtomicUsize::new(0));\n    let mut file = Cursor::new(Vec::new());\n    let mut writer = ProgressWriter::new(\u0026mut file, |progress: usize| {\n        total.fetch_add(progress, Ordering::SeqCst);\n    });\n\n    {\n        let total = total.clone();\n        thread::spawn(move || {\n            loop {\n                println!(\"Written {} Kib\", total.load(Ordering::SeqCst) / 1024);\n                thread::sleep(Duration::from_millis(16));\n            }\n        });\n    }\n\n    let buffer = [0u8; 8192];\n    while total.load(Ordering::SeqCst) \u003c 1000 * 1024 * 1024 {\n        writer.write(\u0026buffer).unwrap();\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpop-os%2Fprogress-streams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpop-os%2Fprogress-streams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpop-os%2Fprogress-streams/lists"}