oneio 0.22.0

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.
Documentation
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# AGENTS.md - oneio Project

Project-specific agent instructions for the oneio library.

---

## Project Overview

**oneio** is a Rust library providing unified I/O for compressed files from any source (local, HTTP, FTP, S3).

- **Repository**: https://github.com/bgpkit/oneio
- **Documentation**: https://docs.rs/oneio
- **License**: MIT

---

## Development Methodology: Spec-Driven Development

This project follows a **lightweight spec-driven development (SDD)** workflow optimized for single-developer/owner projects.

### When to Write a Spec

| Scenario | Spec Required | Location |
|----------|---------------|----------|
| New feature | Yes | `specs/[NN]-[feature-name]/README.md` |
| Bug fix (complex) | Optional | PR description |
| Bug fix (simple) | No | Commit message |
| Refactoring | Yes (if API changes) | `specs/` |
| Dependency updates | No | CHANGELOG.md entry |

### Spec Format

All specs live in `specs/[NN]-[feature-name]/README.md` where `[NN]` is a zero-padded number (01, 02, 03...).

**Required sections:**

```markdown
# Spec: [Feature Name]

**Status**: Draft | In Progress | Complete  
**Author**: [Name]  
**Created**: [Date]  
**Target Branch**: `dev/[feature-name]`

## 1. Overview
- Goal (one sentence)
- Non-goals (what we're NOT doing)
- Success criteria (checkboxes)

## 2. Current State
- What exists now
- What's broken/missing

## 3. Proposed Solution
- Architecture/design
- Key decisions

## 4. Implementation Plan
- Phases with acceptance criteria
- Estimated time per phase

## 5. Testing Strategy
- Unit tests
- Integration tests

## 6. Risks
- What could go wrong
- Mitigation

## 7. Decision Log
- Date: Decision (rationale)
```

### Spec Workflow

```
1. Write spec → 2. Review → 3. Approve → 4. Implement → 5. Verify → 6. Complete
```

**Review checkpoints:**
- After spec writing: Verify scope is clear
- After each phase: Verify acceptance criteria met
- Before merge: Verify against success criteria

---

## Code Style and Conventions

### Rust Style

- **Formatting**: `cargo fmt` (enforced in CI)
- **Linting**: `cargo clippy --all-features -- -D warnings`
- **Edition**: 2021
- **MSRV**: 1.70+ (be conservative)

### Naming Conventions

```rust
// Functions: verb_phrase
pub fn read_to_string(path: &str) -> Result<String>
pub fn s3_upload(bucket: &str, key: &str, file: &str) -> Result<()>

// Structs: PascalCase
pub struct OneIoBuilder
pub struct S3Config

// Constants: SCREAMING_SNAKE_CASE
const CHUNK_SIZE: usize = 8_388_608;

// Feature flags: lowercase with hyphens
// "s3", "native-tls", "async"
```

### Documentation

- **Public APIs**: All public items must have doc comments
- **Examples**: Include usage examples in doc comments
- **CHANGELOG.md**: Update for user-facing changes

```rust
/// Reads a file to string with automatic decompression.
///
/// # Examples
///
/// ```
/// let content = oneio::read_to_string("data.txt.gz")?;
/// ```
///
/// # Errors
///
/// Returns `OneIoError::NotFound` if file doesn't exist.
pub fn read_to_string(path: &str) -> Result<String, OneIoError> {
    // ...
}
```

---

## Testing Requirements

### Before Committing

Run these commands (also enforced in CI):

```bash
cargo fmt --check
cargo build --no-default-features
cargo build --all-features
cargo test --all-features
cargo clippy --all-features -- -D warnings
cargo clippy --no-default-features
```

### Test Organization

```
tests/
├── unit_tests.rs       # Unit tests for internal functions
├── integration_tests/  # Integration tests by feature
│   ├── http_tests.rs
│   ├── s3_tests.rs
│   └── compression_tests.rs
└── fixtures/           # Test data files
```

### Feature-Specific Testing

| Feature | Test Requirements |
|---------|-------------------|
| `s3` | Requires env vars; mark with `#[cfg(test)]` + `#[ignore]` |
| `http` | Use mock servers when possible |
| `ftp` | Requires FTP server; integration tests only |
| Compression | Test with fixture files |

---

## Feature Flags

### Current Flags

| Flag | Description | Dependencies |
|------|-------------|--------------|
| `default` | `gz` + `bz` + `https` | - |
| `gz` | Gzip support | flate2 |
| `bz` | Bzip2 support | bzip2 |
| `lz` | LZ4 support | lz4 |
| `xz` | XZ support | xz2 |
| `zstd` | Zstd support | zstd |
| `http` | HTTP support | reqwest |
| `https` | HTTPS support | reqwest + rustls |
| `ftp` | FTP support | suppaftp |
| `s3` | S3 support | rusty-s3 |
| `async` | Async I/O | tokio |
| `json` | JSON support | serde + serde_json |
| `digest` | Hashing support | ring |
| `cli` | Command-line tool | clap + tracing |

### Adding New Features

1. Add to `[features]` in Cargo.toml
2. Add to feature table in lib.rs docs
3. Gate code with `#[cfg(feature = "...")]`
4. Update CI to test new feature
5. Document in CHANGELOG.md

---

## Git Workflow

### Branch Naming

```
main                    # Production-ready
dev/[description]       # Feature branches
hotfix/[description]    # Urgent fixes
```

### Commit Messages

**Format:** `<type>: <description>`

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation only
- `style`: Formatting (no code change)
- `refactor`: Code restructuring
- `perf`: Performance improvement
- `test`: Adding tests
- `chore`: Maintenance tasks

**Examples:**
```
feat: add S3 multipart upload progress callback
fix: correct gzip decompression for empty files
docs: update README with R2 configuration examples
refactor: extract HTTP client to shared module
```

### Commit Guidelines

- **Keep language factual**: Avoid words like "comprehensive", "extensive", "robust"
- **Good**: "Added R2 endpoint support"
- **Bad**: "Added comprehensive R2 endpoint support with robust error handling"
- **Never include**: Co-authored-by messages for AI agents

---

## Pull Request Process

### Before Creating PR

1. Run full test suite
2. Update CHANGELOG.md
3. Update documentation if needed
4. Review your own diff first

### PR Description Template

```markdown
## Summary
Brief description of changes

## Related Spec
Link to spec document if applicable

## Changes
- List of specific changes

## Testing
- How was this tested?

## Checklist
- [ ] Tests pass
- [ ] CHANGELOG.md updated
- [ ] Documentation updated
- [ ] Spec completed (if applicable)
```

---

## Error Handling

### OneIoError Conventions

```rust
pub enum OneIoError {
    // I/O errors
    Io(std::io::Error),
    
    // Protocol-specific
    NotSupported(String),
    Status { service: &'static str, code: u16 },
    
    // Feature not enabled
    #[cfg(not(feature = "s3"))]
    S3NotEnabled,
}
```

### Error Message Guidelines

- Be specific: `"File not found: {path}"` not `"File error"`
- Include context: `"S3 upload failed for {bucket}/{key}: {source}"`
- User-facing errors should suggest solutions

---

## Dependencies

### Adding New Dependencies

1. Check if already in tree: `cargo tree | grep <crate>`
2. Prefer small, focused crates
3. Check MSRV compatibility
4. Check license compatibility (MIT/Apache-2.0 preferred)
5. Update CHANGELOG.md under "Dependencies"

### Version Constraints

```toml
# Use caret for stable APIs
reqwest = "0.12"

# Pin for unstable or critical deps
rusty-s3 = "=0.9.1"

# Use range for flexibility (rarely)
rustls = ">=0.22, <0.24"
```

---

## Performance Considerations

### Memory

- Stream large files (don't buffer entirely)
- Use ` BufReader`/`BufWriter` for I/O
- Reuse HTTP clients (don't create per-request)

### CPU

- Compression: Use default compression levels
- Hashing: Use streaming for large files
- Avoid unnecessary string allocations

### Network

- Enable connection pooling (reqwest does this)
- Respect S3 multipart thresholds (5MB minimum)
- Use appropriate timeout values

---

## Security

### S3/Credentials

- Never log credentials
- Use environment variables or standard credential chains
- Support IAM roles where possible
- Zeroize credentials in memory when possible

### TLS

- Use rustls (not native-tls) by default
- Enable certificate verification
- Support custom CA certificates

### Input Validation

- Validate paths (no directory traversal)
- Validate URLs (parse, don't construct blindly)
- Sanitize user input in error messages

---

## Release Process

### Version Bumping

Follow [SemVer](https://semver.org/):
- **MAJOR**: Breaking API changes
- **MINOR**: New features (backward compatible)
- **PATCH**: Bug fixes

### Release Checklist

- [ ] Version bumped in Cargo.toml
- [ ] Version references updated in `src/lib.rs` and `README.md` quick-start examples
- [ ] CHANGELOG.md updated with version header
- [ ] Git tag created: `git tag vX.Y.Z`
- [ ] Tests pass on CI
- [ ] Documentation builds
- [ ] crates.io publish: `cargo publish`

---

## Communication

### Questions/Decisions

Document significant decisions in:
1. Spec decision log (for features)
2. Code comments (for implementation details)
3. CHANGELOG.md (for user-facing changes)

### External Resources

- **Rust S3 APIs**: rusty-s3 docs, AWS S3 API reference
- **Compression**: flate2, bzip2, zstd crate docs
- **HTTP**: reqwest docs, hyper docs

---

## Tools and Commands

### Development

```bash
# Build with all features
cargo build --all-features

# Run specific test
cargo test --features s3 s3_upload

# Check formatting
cargo fmt --check

# Run clippy
cargo clippy --all-features -- -D warnings

# Generate docs
cargo doc --all-features --open
```

### Debugging

```bash
# Verbose logging
RUST_LOG=debug cargo run --bin oneio --features cli

# Trace-level S3 operations
RUST_LOG=trace cargo test --features s3 -- --nocapture
```

---

*Last updated: 2025-05-01*