| Crates.io | async-rev-buf |
| lib.rs | async-rev-buf |
| version | 0.1.0 |
| created_at | 2025-06-05 03:30:07.047456+00 |
| updated_at | 2025-06-05 03:30:07.047456+00 |
| description | High-performance async buffered reader for reading lines in reverse order from files and streams |
| homepage | |
| repository | https://github.com/gpmcp/async-jsonl |
| max_upload_size | |
| id | 1701048 |
| size | 63,187 |
A high-performance async buffered reader for reading lines in reverse order from files and streams.
async-rev-buf provides RevBufReader, an async buffered reader that reads lines from the end of a file or stream
backwards to the beginning. This is particularly useful for processing log files, JSON Lines data, or any line-oriented
data where you need the most recent entries first.
lines().next_line().await pattern following tokio conventionsuse async_rev_buf::RevBufReader;
use tokio::fs::File;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("large.log").await?;
let reader = RevBufReader::new(file);
let mut lines = reader.lines();
// Read last 10 lines efficiently
for _ in 0..10 {
if let Some(line) = lines.next_line().await? {
println!("{}", line);
} else {
break;
}
}
Ok(())
}
use async_rev_buf::RevBufReader;
use tokio::fs::File;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("data.txt").await?;
let mut reader = RevBufReader::new(file);
// Read lines in reverse order (last line first)
while let Some(line) = reader.next_line().await? {
println!("{}", line);
}
Ok(())
}
Comprehensive performance comparison against all available async and sync reverse readers:
| Lines | RevBufReader | rev_buf_reader (sync, memory intensive) | tokio-rev-lines | Performance |
|---|---|---|---|---|
| 100 | 9.1M lines/sec | 12.8M lines/sec | 3.8M lines/sec | 2.4x faster |
| 1,000 | 8.5M lines/sec | 12.8M lines/sec | 3.5M lines/sec | 2.4x faster |
| 5,000 | 8.4M lines/sec | 13.1M lines/sec | 3.3M lines/sec | 2.5x faster |
🏆 Outstanding Async Performance:
🎯 When to Choose Our RevBufReader:
📊 Competitive Analysis:
cargo bench --bench comparison
Purpose-Built for Reverse Reading:
Instead of forcing compatibility with AsyncBufRead (which would cause 50-70% performance loss), we provide a clean,
purpose-built API optimized specifically for reverse reading.
Benefits of Current Design:
Technical Constraints:
AsyncSeek - works with files but not all streams\n and \r\n boundariesAsyncBufRead trait (by design for performance)Performance Context:
Contributions welcome! Please feel free to submit issues, feature requests, or pull requests.
Focus Areas:
Part of the async-jsonl ecosystem for efficient async JSON Lines processing.