#azure #http #aws

cloud-file

Simple reading of cloud files in Rust

8 releases

0.2.0 Oct 17, 2024
0.1.2 Mar 6, 2024
0.1.1 Feb 8, 2024
0.1.0-beta.2 Jan 29, 2024

#734 in HTTP client

Download history 39/week @ 2026-01-27 37/week @ 2026-02-03 236/week @ 2026-02-10 184/week @ 2026-02-17 69/week @ 2026-02-24 42/week @ 2026-03-03 75/week @ 2026-03-10 98/week @ 2026-03-17 118/week @ 2026-03-24 214/week @ 2026-03-31 158/week @ 2026-04-07 158/week @ 2026-04-14 181/week @ 2026-04-21 208/week @ 2026-04-28 180/week @ 2026-05-05 142/week @ 2026-05-12

752 downloads per month
Used in bed-reader

MIT/Apache

46KB
387 lines

cloud-file

github crates.io docs.rs build status

Simple reading of cloud files in Rust

Highlights

Install

cargo add cloud-file

Examples

Find the size of a cloud file.

use cloud_file::CloudFile;
# Runtime::new().unwrap().block_on(async {  // '#' needed for doctest

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/toydata.5chrom.fam";
let cloud_file = CloudFile::new(url)?;
let file_size = cloud_file.read_file_size().await?;
assert_eq!(file_size, 14_361);
# Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
# use {cloud_file::CloudFileError, tokio::runtime::Runtime};

Find the number of lines in a cloud file.

use cloud_file::CloudFile;
use futures::StreamExt; // Enables `.next()` on streams.
# Runtime::new().unwrap().block_on(async { // '#' needed for doctest

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/toydata.5chrom.fam";
let cloud_file = CloudFile::new_with_options(url, [("timeout", "30s")])?;
let mut chunks = cloud_file.stream_chunks().await?;
let mut newline_count: usize = 0;
while let Some(chunk) = chunks.next().await {
    let chunk = chunk?;
    newline_count += bytecount::count(&chunk, b'\n');
}
assert_eq!(newline_count, 500);
# Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
# use {cloud_file::CloudFileError, tokio::runtime::Runtime};   

More examples

Example Demonstrates
line_count Read a file as binary chunks.
nth_line Read a file as text lines.
bigram_counts Read random regions of a file, without regard to order.
aws_file_size Find the size of a file on AWS.

Dependencies

~13–20MB
~267K SLoC