| Crates.io | oneio |
| lib.rs | oneio |
| version | 0.19.0 |
| created_at | 2022-08-02 19:01:02.011328+00 |
| updated_at | 2025-09-01 01:16:20.933568+00 |
| description | OneIO is a Rust library that provides unified simple IO interface for reading and writing to and from data files from different sources and compressions. |
| homepage | |
| repository | https://github.com/bgpkit/oneio |
| max_upload_size | |
| id | 637517 |
| size | 208,169 |
OneIO is a Rust library providing unified IO operations for reading and writing compressed files from local and remote sources with both synchronous and asynchronous support.
oneio = "0.19" # Default: gz, bz, https
Local files only:
oneio = { version = "0.19", default-features = false, features = ["gz", "bz"] }
HTTP only (no HTTPS):
oneio = { version = "0.19", default-features = false, features = ["http", "gz"] }
HTTPS with default rustls:
oneio = { version = "0.19", default-features = false, features = ["https", "gz"] }
HTTPS with custom TLS backend:
# With rustls
oneio = { version = "0.19", default-features = false, features = ["http", "rustls", "gz"] }
# With native-tls
oneio = { version = "0.19", default-features = false, features = ["http", "native-tls", "gz"] }
S3-compatible storage:
oneio = { version = "0.19", default-features = false, features = ["s3", "https", "gz"] }
Async operations:
oneio = { version = "0.19", features = ["async"] }
Compression (choose only what you need):
gz - Gzip via flate2bz - Bzip2lz - LZ4xz - XZzstd - Zstandard (balanced)Protocols:
http - HTTP-only support (no TLS)https - HTTP/HTTPS with rustls TLS backend (equivalent to http + rustls)ftp - FTP support (requires http + TLS backend)s3 - S3-compatible storageTLS Backends (for HTTPS - mutually exclusive):
rustls - Pure Rust TLS (use with http)native-tls - Platform native TLS (use with http)Additional:
async - Async support (limited to gz, bz, zstd for compression)json - JSON parsingdigest - SHA256 digest calculationcli - Command-line toolEnvironment: Set ONEIO_ACCEPT_INVALID_CERTS=true to accept invalid certificates.
Read all content into a string:
use oneio;
const TEST_TEXT: &str = "OneIO test file.\nThis is a test.";
// Works with compression and remote files automatically
let content = oneio::read_to_string("https://spaces.bgpkit.org/oneio/test_data.txt.gz")?;
assert_eq!(content.trim(), TEST_TEXT);
Read line by line:
use oneio;
let lines = oneio::read_lines("https://spaces.bgpkit.org/oneio/test_data.txt.gz")?
.map(|line| line.unwrap())
.collect::<Vec<String>>();
assert_eq!(lines.len(), 2);
assert_eq!(lines[0], "OneIO test file.");
assert_eq!(lines[1], "This is a test.");
Get a reader for streaming:
use oneio;
use std::io::Read;
let mut reader = oneio::get_reader("tests/test_data.txt.gz")?;
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer)?;
Write with automatic compression:
use oneio;
use std::io::Write;
let mut writer = oneio::get_writer("output.txt.gz")?;
writer.write_all(b"Hello, compressed world!")?;
drop(writer); // Important: close the writer
// Read it back
let content = oneio::read_to_string("output.txt.gz")?;
assert_eq!(content, "Hello, compressed world!");
use oneio;
let client = oneio::create_client_with_headers([("Authorization", "Bearer TOKEN")])?;
let mut reader = oneio::get_http_reader(
"https://api.example.com/protected/data.json.gz",
Some(client)
)?;
let content = std::io::read_to_string(&mut reader)?;
println!("{}", content);
Track download/read progress with callbacks:
use oneio;
let (mut reader, total_size) = oneio::get_reader_with_progress(
"https://example.com/largefile.gz",
|bytes_read, total_bytes| {
match total_bytes {
Some(total) => {
let percent = (bytes_read as f64 / total as f64) * 100.0;
println!("Progress: {:.1}%", percent);
}
None => println!("Downloaded: {} bytes", bytes_read),
}
}
)?;
async)use oneio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let content = oneio::read_to_string_async("https://example.com/data.json.gz").await?;
oneio::download_async(
"https://example.com/data.csv.gz",
"local_data.csv.gz"
).await?;
Ok(())
}
Note: Async compression is limited to gz, bz, zstd. LZ4/XZ return NotSupported.
OneIO detects compression algorithm by the file extensions:
.gz, .gzip.bz, .bz2.lz4, .lz.xz, .xz2.zst, .zstd/path/to/file.txthttps://example.com/file.txt.gzftp://ftp.example.com/file.txt (requires ftp feature)s3://bucket/path/file.txt (requires s3 feature)Install the CLI tool:
cargo install oneio --features cli
Basic usage:
# Read and print a remote compressed file
oneio https://example.com/data.txt.gz
# Download a file
oneio -d https://example.com/largefile.bz2
# Pipe to other tools
oneio https://api.example.com/data.json.gz | jq '.results | length'
s3)use oneio::s3::*;
// Direct S3 operations
s3_upload("my-bucket", "path/to/file.txt", "local/file.txt")?;
s3_download("my-bucket", "path/to/file.txt", "downloaded.txt")?;
// Read S3 directly
let content = oneio::read_to_string("s3://my-bucket/path/to/file.txt")?;
// Check existence and get metadata
if s3_exists("my-bucket", "path/to/file.txt")? {
let stats = s3_stats("my-bucket", "path/to/file.txt")?;
println!("Size: {} bytes", stats.content_length.unwrap_or(0));
}
// List objects
let objects = s3_list("my-bucket", "path/", Some("/".to_string()), false)?;
Three error types in v0.19:
use oneio::OneIoError;
match oneio::get_reader("file.txt") {
Ok(reader) => { /* use reader */ },
Err(OneIoError::Io(e)) => { /* filesystem error */ },
Err(OneIoError::Network(e)) => { /* network error */ },
Err(OneIoError::NotSupported(msg)) => { /* feature not compiled */ },
}
MIT