OneIO - all-in-one IO library for Rust
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.
Quick Start
= "0.20" # Default: gz, bz, https
Feature Selection Guide
Common Use Cases
Local files only:
= { = "0.20", = false, = ["gz", "bz"] }
HTTPS with default rustls:
= { = "0.20", = false, = ["https", "gz"] }
HTTPS with custom TLS backend:
# With rustls
= { = "0.20", = false, = ["http", "rustls", "gz"] }
# With native-tls (recommended for corporate proxies/VPNs)
= { = "0.20", = false, = ["http", "native-tls", "gz"] }
S3-compatible storage:
= { = "0.20", = false, = ["s3", "https", "gz"] }
Async operations:
= { = "0.20", = ["async"] }
Available Features
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 tohttp+rustls)ftp- FTP support (requireshttp+ TLS backend)s3- S3-compatible storage
TLS Backends (for HTTPS - mutually exclusive):
rustls- Pure Rust TLS (use withhttp). Uses both system certificates and bundled Mozilla certificates for maximum compatibility.native-tls- Platform native TLS (use withhttp). Recommended for corporate proxies and VPNs (Cloudflare WARP, etc.) as it uses the OS trust store.
Additional:
async- Async support (limited to gz, bz, zstd for compression)json- JSON parsingdigest- SHA256 digest calculationcli- Command-line tool
Working with Corporate Proxies (Cloudflare WARP, etc.)
If you're behind a corporate proxy or VPN like Cloudflare WARP that uses custom TLS certificates:
[]
= { = "0.20", = false, = ["http", "native-tls", "gz"] }
The native-tls feature uses your operating system's TLS stack with its trust store, which includes custom corporate certificates. This works for both HTTP/HTTPS and S3 operations.
Alternatively, you can add custom CA certificates:
use OneIo;
let oneio = builder
.add_root_certificate_pem?
.build?;
Or set the ONEIO_CA_BUNDLE environment variable:
Environment Variables:
ONEIO_ACCEPT_INVALID_CERTS=true- Accept invalid TLS certificates (insecure, for development only)ONEIO_CA_BUNDLE=/path/to/ca.pem- Add custom CA certificate to trust store
Library Usage
Basic Reading and Writing
Read all content into a string (works with compression and remote files automatically):
use oneio;
let content = read_to_string?;
println!;
Read line by line:
use oneio;
let lines = read_lines?
.map
.;
for line in lines
Get a reader for streaming:
use oneio;
use Read;
let mut reader = get_reader?;
let mut buffer = Vecnew;
reader.read_to_end?;
Write with automatic compression:
use oneio;
use Write;
let mut writer = get_writer?;
writer.write_all?;
drop; // Important: close the writer
// Read it back
let content = read_to_string?;
Reusable OneIo Clients
The OneIo client allows you to configure headers, TLS certificates, timeouts, and other options once, then reuse the configuration across multiple operations:
use OneIo;
use ;
// Build a reusable client with custom headers and certificates
let oneio = builder
.header_str
.add_root_certificate_pem?
.timeout
.connect_timeout
.build?;
// Reuse the same configuration for multiple requests
let content1 = oneio.read_to_string?;
let content2 = oneio.read_to_string?;
Builder Methods:
.header(name, value)- Add a typed header (infallible, usesHeaderNameandHeaderValue).header_str(name, value)- Add a string header (panics on invalid input).user_agent(value)- Set User-Agent header.add_root_certificate_pem(pem)- Add custom CA certificate (PEM format).add_root_certificate_der(der)- Add custom CA certificate (DER format).danger_accept_invalid_certs(true)- Accept invalid certificates.timeout(duration)- Set request timeout.connect_timeout(duration)- Set connection timeout.proxy(proxy)- Set HTTP proxy.no_proxy()- Disable system proxy.redirect(policy)- Set redirect policy.configure_http(f)- Escape hatch for direct reqwest configuration
Compression Override
For URLs with query parameters or non-standard extensions, use explicit compression type:
use OneIo;
let oneio = new?;
// URL has query params, so we specify compression explicitly
let reader = oneio.get_reader_with_type?;
Progress Tracking
Track download/read progress with callbacks:
use OneIo;
let oneio = new?;
// Callback receives (bytes_read, total_bytes).
// total_bytes is 0 when the server does not provide a Content-Length.
// The returned Option<u64> is Some(total) when the size was known upfront.
let = oneio.get_reader_with_progress?;
Async Support (Feature: async)
use oneio;
async
Note: Async compression is limited to gz, bz, zstd. LZ4/XZ return NotSupported.
S3 Operations (Feature: s3)
use *;
// Direct S3 operations
s3_upload?;
s3_download?;
// Read S3 directly using OneIO
let oneio = new?;
let content = oneio.read_to_string?;
// Check existence and get metadata
if s3_exists?
// List objects
let objects = s3_list?;
Required environment variables for S3:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGION(use "auto" for Cloudflare R2)AWS_ENDPOINT
Error Handling
OneIO uses a simplified error enum with #[non_exhaustive] for forward compatibility:
use OneIoError;
match get_reader
Crypto Provider Initialization (Rustls)
When using HTTPS, S3, or FTP features with rustls, oneio automatically initializes a crypto provider (AWS-LC or ring) on first use. For more control, initialize it explicitly:
use oneio;
Command Line Tool
Install the CLI tool:
Basic Usage
Read and print a remote compressed file:
Read local compressed file:
Get file statistics:
Download with Progress Bar
Download a file with automatic progress bar (shown when stderr is a terminal):
When stderr is piped or redirected the progress bar is suppressed.
Custom HTTP Headers
Add custom headers for API authentication:
Compression Override
For URLs with query parameters where extension detection fails:
Caching
Cache remote files locally for repeated reads:
# Second read uses cache
Force re-download even if cache exists:
S3 Operations
Upload file to S3:
Download file from S3:
List S3 bucket:
List directories only:
Generate SHA256 Digest
)
CLI Help Output
$ oneio --help
oneio reads files from local or remote locations with any compression
Usage: oneio [OPTIONS] [FILE] [COMMAND]
Commands:
s3 S3-related subcommands
digest Generate SHA256 digest
help Print this message or the given subcommand(s)
Arguments:
[FILE] file to open, remote or local
Options:
-d, --download download the file to the current directory
-o, --outfile <OUTFILE> output file path
--cache-dir <CACHE_DIR> cache reading to a specified directory
--cache-force force re-caching if a local cache already exists
--cache-file <CACHE_FILE> specify cache file name
-s, --stats read through the file and only print out stats
-H, --header <HEADERS> Add HTTP header (format: "Name: Value"), can be repeated
--compression <COMPRESSION> Override compression type (gz, bz2, lz4, xz, zst)
-h, --help Print help
-V, --version Print version
Supported Formats
Compression Detection
OneIO detects compression algorithm by the file extensions:
- Gzip:
.gz,.gzip,.tgz - Bzip2:
.bz,.bz2 - LZ4:
.lz4,.lz - XZ:
.xz,.xz2,.lzma - Zstandard:
.zst,.zstd
For URLs with query parameters, use --compression flag or get_reader_with_type().
Protocol Support
- Local files:
/path/to/file.txt - HTTP/HTTPS:
https://example.com/file.txt.gz - FTP:
ftp://ftp.example.com/file.txt(requiresftpfeature) - S3:
s3://bucket/path/file.txt(requiress3feature)
License
MIT