OneIO
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.
Usage and Feature Flags
Enable all compression algorithms, and handle remote files (default)
= "0.1"
Select from supported feature flags
= { = "0.1", = ["remote", "gz"]}
Supported feature flags:
all(default): all flags (["gz", "bz", "lz", "remote"])remote: allow reading from remote filesgz: supportgzipfilesbz: supportbzip2fileslz: supportlz4files
OneIO Reader
The returned reader implements BufRead, and handles decompression from the following types:
gzip: files ending withgzorgzipbzip2: files ending withbzorbz2lz4: files ending withlz4orlz
It also handles reading from remote or local files transparently.
Examples
Read all into string:
const TEST_TEXT: &str = "OneIO test file.
This is a test.";
let mut reader = get_reader.unwrap;
let mut text = "".to_string;
reader.read_to_string.unwrap;
assert_eq!;
Read into lines:
use BufRead;
const TEST_TEXT: &str = "OneIO test file.
This is a test.";
let reader = get_reader.unwrap;
let lines = reader.lines.into_iter.map.;
assert_eq!;
assert_eq!;
assert_eq!;
OneIO Writer
[get_writer] returns a generic writer that implements [Write], and handles decompression from the following types:
gzip: files ending withgzorgzipbzip2: files ending withbzorbz2
Note: lz4 writer is not currently supported.
Example
let to_read_file = "https://spaces.bgpkit.org/oneio/test_data.txt.gz";
let to_write_file = "/tmp/test_write.txt.bz2";
// read text from remote gzip file
let mut text = "".to_string;
get_reader.unwrap.read_to_string.unwrap;
// write the same text to a local bz2 file
let mut writer = get_writer.unwrap;
writer.write_all.unwrap;
drop;
// read from the newly-generated bz2 file
let mut new_text = "".to_string;
get_reader.unwrap.read_to_string.unwrap;
// compare the decompressed content of the remote and local files
assert_eq!;
remove_file.unwrap;