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"] }
HTTP only (no HTTPS):
= { = "0.20", = false, = ["http", "gz"] }
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
= { = "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)native-tls- Platform native TLS (use withhttp)
Additional:
async- Async support (limited to gz, bz, zstd for compression)json- JSON parsingdigest- SHA256 digest calculationcli- Command-line tool
Environment: Set ONEIO_ACCEPT_INVALID_CERTS=true to accept invalid certificates.
Crypto Provider Initialization: When using rustls features (https, s3, ftp), oneio
automatically initializes the crypto provider (AWS-LC or ring) on first use. You can also
initialize it explicitly at startup using [crypto::ensure_default_provider()] for better
control over error handling.
Usages
Reading Files
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 = read_to_string?;
assert_eq!;
Read line by line:
use oneio;
let lines = read_lines?
.map
.;
assert_eq!;
assert_eq!;
assert_eq!;
Get a reader for streaming:
use oneio;
use Read;
let mut reader = get_reader?;
let mut buffer = Vecnew;
reader.read_to_end?;
Writing Files
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?;
assert_eq!;
Remote Files with Custom Headers
use oneio;
let client = create_client_with_headers?;
let mut reader = get_http_reader?;
let content = read_to_string?;
println!;
Progress Tracking
Track download/read progress with callbacks:
use oneio;
let = get_reader_with_progress?;
Async Support (Feature: async)
use oneio;
async
Note: Async compression is limited to gz, bz, zstd. LZ4/XZ return NotSupported.
Supported Formats
Compression Detection
OneIO detects compression algorithm by the file extensions:
- Gzip:
.gz,.gzip - Bzip2:
.bz,.bz2 - LZ4:
.lz4,.lz - XZ:
.xz,.xz2 - Zstandard:
.zst,.zstd
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)
Command Line Tool
Install the CLI tool:
Basic usage:
# Read and print a remote compressed file
# Download a file
# Pipe to other tools
|
S3 Operations (Feature: s3)
use *;
// Direct S3 operations
s3_upload?;
s3_download?;
// Read S3 directly
let content = read_to_string?;
// Check existence and get metadata
if s3_exists?
// List objects
let objects = s3_list?;
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, you can initialize it explicitly at startup:
use oneio;
This is particularly useful in libraries or applications that want to:
- Handle initialization errors early
- Control when the provider is set up
- Make the dependency on crypto providers explicit
Error Handling
Three error types in v0.20:
use OneIoError;
match get_reader
License
MIT