dsq-io
I/O utilities for DSQ - handles reading and writing to disk, STDIN, STDOUT.
Overview
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.
Features
- Multiple sources: Files, STDIN, pipes
- Multiple destinations: Files, STDOUT, STDERR
- Streaming I/O: Efficient processing of large datasets
- Async support: Non-blocking I/O with Tokio
- Format-aware: Integrates with dsq-formats for automatic format detection
- Error handling: Comprehensive error types for I/O operations
- Buffer management: Configurable buffering strategies
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Usage
Reading from Files
use read_file;
async
Reading from STDIN
use read_stdin;
async
Writing to Files
use write_file;
async
Writing to STDOUT
use write_stdout;
async
Streaming Data
use ;
use AsyncBufReadExt;
async
Auto-detecting Format
use read_data_file;
use Format;
async
API Components
Input Sources
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 detection
Output Destinations
write_file(): Write to a file pathwrite_stdout(): Write to standard outputwrite_stderr(): Write to standard errorwrite_bytes(): Write raw bytes
Streaming
StreamReader: Async buffered readerStreamWriter: Async buffered writerLineReader: Line-by-line readingChunkReader: Chunked reading for large files
Utilities
detect_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 file
Configuration
Buffer Sizes
use ;
let config = IoConfig ;
let reader = with_config
.await?;
Error Handling
use ;
async
Platform Support
- Linux: Full support
- macOS: Full support
- Windows: Full support
- WASM: Limited support (no file system access)
API Documentation
For detailed API documentation, see docs.rs/dsq-io.
Performance
I/O operations are optimized for:
- Large file handling with buffering
- Async I/O to prevent blocking
- Memory-efficient streaming
- Minimal system calls
Contributing
Contributions are welcome! Please see the CONTRIBUTING.md file in the repository root for guidelines.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.