{"id":21423795,"url":"https://github.com/ossystems/tokio-take-seek","last_synced_at":"2025-10-28T23:02:43.345Z","repository":{"id":62444764,"uuid":"446590471","full_name":"OSSystems/tokio-take-seek","owner":"OSSystems","description":"This crate offers a async take implementation that supports seek operation","archived":false,"fork":false,"pushed_at":"2022-06-08T18:51:55.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-09-03T16:11:21.957Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OSSystems.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-01-10T21:41:12.000Z","updated_at":"2023-07-25T14:53:16.000Z","dependencies_parsed_at":"2022-11-01T23:33:43.596Z","dependency_job_id":null,"html_url":"https://github.com/OSSystems/tokio-take-seek","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/OSSystems/tokio-take-seek","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Ftokio-take-seek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Ftokio-take-seek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Ftokio-take-seek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Ftokio-take-seek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OSSystems","download_url":"https://codeload.github.com/OSSystems/tokio-take-seek/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSSystems%2Ftokio-take-seek/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278322147,"owners_count":25967873,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-22T21:18:12.043Z","updated_at":"2025-10-04T13:50:47.209Z","avatar_url":"https://github.com/OSSystems.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tokio-take-seek\n\nThis creates offers a wraparound to `tokio::io::Take` that offers a `tokio::io::AsyncSeek`\nimplementation (as long as the inner handle used implements it as well). The idea is to\nuse the `Take` implementation as a _upper bound_ and not allow reads beyond that point,\nand when `seek` operations are called, the underling limit of how many bytes can still be\nread is properly updated.\n\nThe provided `AsyncTakeSeekExt` trait offers a `take_with_seek` method for creating the\nwrapper over any type that implements `AsyncRead + AsyncSeek + Unpin`.\n\n## Implementation\n\nThe current implementation has to do internally two seeks for every `seek` called. The\nfirst `seek` is done with `SeekFrom::current(0)` and it's result is used to determine how\nmuch the stream has moved so the `Take`'s inner limit can be properly updated.\n\n## Usage example:\n\nOn this example we use the `take_with_seek` to guarantee that the string won't be read\nbeyond the desired limit, while still being able to seek over the reader even after the\nbound is created.\n\n```Rust\nasync fn basic_seek_and_reed() {\n    let file = tempfile::NamedTempFile::new().unwrap();\n    //                                        21v               38v\n    fs::write(file.path(), \"this will be skipped|this will be read|this will be guarded\")\n        .await\n        .unwrap();\n\n    let mut handle = TakeSeek::new(take::take(fs::File::open(file.path()).await.unwrap(), 38));\n    handle.seek(SeekFrom::Start(21)).await.unwrap();\n\n    let mut data = String::default();\n    handle.read_to_string(\u0026mut data).await.unwrap();\n    assert_eq!(data, \"this will be read\");\n}\n\n``` \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossystems%2Ftokio-take-seek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fossystems%2Ftokio-take-seek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossystems%2Ftokio-take-seek/lists"}