1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*!
Unified I/O for compressed files from any source.
OneIO provides a single interface for reading and writing files with any
compression format, from local disk or remote locations (HTTP, FTP, S3).
# Quick Start
```toml
[dependencies]
oneio = "0.22"
```
```rust,no_run
# fn main() -> Result<(), Box<dyn std::error::Error>> {
use oneio;
// Read a remote compressed file
let content = oneio::read_to_string("https://example.com/data.txt.gz")?;
# Ok(())
# }
```
# Feature Selection
Enable only what you need:
| Feature | Description |
|---------|-------------|
| `gz` | Gzip compression |
| `bz` | Bzip2 compression |
| `lz` | LZ4 compression |
| `xz` | XZ compression |
| `zstd` | Zstandard compression |
| `http` | HTTP/HTTPS support |
| `ftp` | FTP support |
| `s3` | S3-compatible storage |
| `async` | Async I/O support |
| `json` | JSON deserialization |
| `digest` | SHA256 hashing |
| `cli` | Command-line tool |
**Example: Minimal setup for local files**
```toml
[dependencies]
oneio = { version = "0.22", default-features = false, features = ["gz"] }
```
**Example: HTTPS with custom TLS for corporate proxies**
```toml
[dependencies]
oneio = { version = "0.22", default-features = false, features = ["http", "native-tls", "gz"] }
```
# Core API
## Reading
```rust,no_run
# fn main() -> Result<(), Box<dyn std::error::Error>> {
// Read entire file to string
let content = oneio::read_to_string("data.txt")?;
// Read lines
for line in oneio::read_lines("data.txt")? {
println!("{}", line?);
}
// Get a reader for streaming
let mut reader = oneio::get_reader("data.txt.gz")?;
# Ok(())
# }
```
## Writing
```rust,no_run
# fn main() -> Result<(), Box<dyn std::error::Error>> {
use std::io::Write;
let mut writer = oneio::get_writer("output.txt.gz")?;
writer.write_all(b"Hello")?;
// Compression finalized on drop
# Ok(())
# }
```
## Reusable Client
For multiple requests with shared configuration:
```rust,no_run
# #[cfg(feature = "http")]
# fn main() -> Result<(), Box<dyn std::error::Error>> {
use oneio::OneIo;
let client = OneIo::builder()
.header_str("Authorization", "Bearer token")
.timeout(std::time::Duration::from_secs(30))
.build()?;
let data1 = client.read_to_string("https://api.example.com/1.json")?;
let data2 = client.read_to_string("https://api.example.com/2.json")?;
# Ok(())
# }
# #[cfg(not(feature = "http"))]
# fn main() {}
```
# Compression
Automatic detection by file extension:
| Extension | Algorithm |
|-----------|-----------|
| `.gz` | Gzip |
| `.bz2` | Bzip2 |
| `.lz4` | LZ4 |
| `.xz` | XZ |
| `.zst` | Zstandard |
Override detection for URLs with query parameters:
```rust,no_run
# fn main() -> Result<(), Box<dyn std::error::Error>> {
use oneio::OneIo;
let client = OneIo::new()?;
let reader = client.get_reader_with_type(
"https://api.example.com/data?format=gz",
"gz"
)?;
# Ok(())
# }
```
# Protocols
- **Local**: `/path/to/file.txt`
- **HTTP/HTTPS**: `https://example.com/file.txt.gz`
- **FTP**: `ftp://ftp.example.com/file.txt` (requires `ftp` feature)
- **S3**: `s3://bucket/key` (requires `s3` feature)
# Async API
Enable the `async` feature:
```rust
# #[cfg(feature = "async")]
# async fn example() -> Result<(), oneio::OneIoError> {
let content = oneio::read_to_string_async("https://example.com/data.txt").await?;
# Ok(())
# }
```
Async compression support: `gz`, `bz`, `zstd`
LZ4 and XZ return `NotSupported` error.
# Error Handling
```rust,no_run
# fn main() -> Result<(), Box<dyn std::error::Error>> {
use oneio::OneIoError;
match oneio::get_reader("file.txt") {
Ok(reader) => { /* ... */ }
Err(OneIoError::Io(e)) => { /* filesystem error */ }
Err(OneIoError::Network(e)) => { /* network error */ }
Err(OneIoError::NotSupported(msg)) => { /* feature not enabled */ }
_ => { /* future error variants */ }
}
# Ok(())
# }
```
# Environment Variables
## General
- `ONEIO_ACCEPT_INVALID_CERTS=true` - Accept invalid TLS certificates (development only)
- `ONEIO_CA_BUNDLE=/path/to/ca.pem` - Add custom CA certificate to trust store
## S3 (requires `s3` feature)
Required:
- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
- `AWS_REGION` - Use `"auto"` for Cloudflare R2
- `AWS_ENDPOINT` - e.g. `https://xxx.r2.cloudflarestorage.com`
Optional:
- `AWS_SESSION_TOKEN` - Temporary session token
- `ONEIO_S3_CHUNK_SIZE` - Multipart part size in bytes (default: 8MB)
- `ONEIO_S3_MULTIPART_THRESHOLD` - File size threshold for multipart upload (default: 5MB)
R2 supports single PUT uploads up to 300 MiB. The default threshold of 5MB
(the S3 minimum part size) uses single-PUT for small files and multipart
for larger files where retry-per-part improves reliability.
# TLS and Corporate Proxies
For environments with custom TLS certificates (Cloudflare WARP, corporate proxies):
1. Use `native-tls` feature to use the OS trust store:
```toml
features = ["http", "native-tls"]
```
2. Or add certificates programmatically:
```rust,no_run
# #[cfg(feature = "http")]
# fn main() -> Result<(), Box<dyn std::error::Error>> {
# use oneio::OneIo;
let client = OneIo::builder()
.add_root_certificate_pem(&std::fs::read("ca.pem")?)?
.build()?;
# Ok(())
# }
# #[cfg(not(feature = "http"))]
# fn main() {}
```
3. Or via environment variable:
```bash
export ONEIO_CA_BUNDLE=/path/to/ca.pem
```
*/
pub use OneIoBuilder;
pub use OneIo;
pub use OneIoError;
pub
// Re-export all s3 functions
pub use *;
// Re-export all digest functions
pub use *;
use File;
use ;
// Internal helpers
/// Extracts the protocol from a given path.
pub
/// Extract the file extension, ignoring URL query params and fragments.
pub
/// Creates a raw writer without compression.
pub
/// Creates a raw reader for local files.
pub
/// Gets a reader for the given file path.
/// Returns a writer for the given file path with the corresponding compression.
/// Checks whether a local or remote path exists.
/// Reads the full contents of a file or URL into a string.
/// Reads and deserializes JSON into the requested type.
/// Returns an iterator over lines from the provided path.
/// Downloads a remote resource to a local path.
/// Creates a reader backed by a local cache file.
/// Gets an async reader for the given file path.
pub async
/// Reads the entire content of a file asynchronously into a string.
pub async
/// Downloads a file asynchronously from a URL to a local path.
pub async