| Crates.io | dsq-io |
| lib.rs | dsq-io |
| version | 0.1.0 |
| created_at | 2025-12-15 17:50:08.303704+00 |
| updated_at | 2025-12-15 17:50:08.303704+00 |
| description | I/O utilities for dsq - handles reading and writing to disk, STDIN, STDOUT |
| homepage | |
| repository | https://github.com/durableprogramming/dsq |
| max_upload_size | |
| id | 1986452 |
| size | 175,365 |
I/O utilities for DSQ - handles reading and writing to disk, STDIN, STDOUT.
dsq-io provides I/O abstractions and utilities for the DSQ ecosystem. It handles reading from various sources (files, STDIN, URLs) and writing to various destinations (files, STDOUT, STDERR), with support for streaming, buffering, and format detection.
Add this to your Cargo.toml:
[dependencies]
dsq-io = "0.1"
use dsq_io::read_file;
#[tokio::main]
async fn main() {
let data = read_file("data.json")
.await
.expect("Failed to read file");
println!("Read {} bytes", data.len());
}
use dsq_io::read_stdin;
#[tokio::main]
async fn main() {
let data = read_stdin()
.await
.expect("Failed to read from STDIN");
println!("Received {} bytes from STDIN", data.len());
}
use dsq_io::write_file;
#[tokio::main]
async fn main() {
let data = b"Hello, World!";
write_file("output.txt", data)
.await
.expect("Failed to write file");
}
use dsq_io::write_stdout;
#[tokio::main]
async fn main() {
let data = b"Result data";
write_stdout(data)
.await
.expect("Failed to write to STDOUT");
}
use dsq_io::{StreamReader, StreamWriter};
use tokio::io::AsyncBufReadExt;
#[tokio::main]
async fn main() {
let mut reader = StreamReader::from_file("large_file.csv")
.await
.expect("Failed to open file");
let mut writer = StreamWriter::to_file("output.csv")
.await
.expect("Failed to create output file");
// Process line by line
let mut lines = reader.lines();
while let Some(line) = lines.next_line().await.unwrap() {
// Process line
writer.write_line(&line).await.expect("Failed to write");
}
writer.flush().await.expect("Failed to flush");
}
use dsq_io::read_data_file;
use dsq_formats::Format;
#[tokio::main]
async fn main() {
// Automatically detects format and parses
let (format, dataframe) = read_data_file("data.csv")
.await
.expect("Failed to read data file");
println!("Detected format: {:?}", format);
println!("Loaded {} rows", dataframe.height());
}
read_file(): Read from a file pathread_stdin(): Read from standard inputread_bytes(): Read raw bytesread_data_file(): Read and parse data file with format detectionwrite_file(): Write to a file pathwrite_stdout(): Write to standard outputwrite_stderr(): Write to standard errorwrite_bytes(): Write raw bytesStreamReader: Async buffered readerStreamWriter: Async buffered writerLineReader: Line-by-line readingChunkReader: Chunked reading for large filesdetect_source_type(): Determine if input is file, STDIN, or pipeis_tty(): Check if output is a terminalensure_directory(): Create directory if it doesn't existtemp_file(): Create temporary fileuse dsq_io::{IoConfig, StreamReader};
let config = IoConfig {
buffer_size: 64 * 1024, // 64 KB buffer
read_timeout: Some(Duration::from_secs(30)),
..Default::default()
};
let reader = StreamReader::with_config("file.dat", config)
.await?;
use dsq_io::{read_file, IoError};
#[tokio::main]
async fn main() {
match read_file("missing.txt").await {
Ok(data) => println!("Success: {} bytes", data.len()),
Err(IoError::FileNotFound(path)) => {
eprintln!("File not found: {}", path);
}
Err(IoError::PermissionDenied(path)) => {
eprintln!("Permission denied: {}", path);
}
Err(e) => eprintln!("I/O error: {}", e),
}
}
For detailed API documentation, see docs.rs/dsq-io.
I/O operations are optimized for:
Contributions are welcome! Please see the CONTRIBUTING.md file in the repository root for guidelines.
Licensed under either of:
at your option.