20 releases
0.1.20 | Jun 9, 2024 |
---|---|
0.1.19 | Feb 12, 2023 |
0.1.18 | Jan 27, 2023 |
0.1.15 | Jun 13, 2022 |
0.1.3 | Nov 26, 2021 |
#86 in Memory management
1,076 downloads per month
Used in 2 crates
72KB
1.5K
SLoC
rabuf
The Buffer for random access file.
When you read and write a file,
this read and write in Chunk
units and reduce IO operation.
Features
- random access
Chunk
units os io operation- reduce os io operation
- support small size access accel.
- minimum support rustc 1.56.1 (59eed8a2a 2021-11-01)
Examples
Write, Seek, Read
use rabuf::BufFile;
use std::fs::OpenOptions;
use std::io::{Read, Seek, SeekFrom, Write};
std::fs::create_dir_all("target/tmp").unwrap();
let path = "target/tmp/doc_test_1";
let bw = b"ABCEDFG\nhijklmn\n";
let f = OpenOptions::new().create(true)
.read(true).write(true).open(path).unwrap();
let mut bf = BufFile::new("tes", f).unwrap();
bf.write_all(bw).unwrap();
bf.seek(SeekFrom::Start(0)).unwrap();
let mut br = vec![0u8; bw.len()];
bf.read_exact(&mut br).unwrap();
assert_eq!(&br, bw);
Write, Close, Open, Read
use rabuf::BufFile;
use std::fs::OpenOptions;
use std::io::{Read, Seek, SeekFrom, Write};
std::fs::create_dir_all("target/tmp").unwrap();
let path = "target/tmp/doc_test_2";
let bw = b"abcdefg\nHIJKLMN\n";
{
let f = OpenOptions::new().create(true)
.read(true).write(true).open(path).unwrap();
let mut bf = BufFile::new("tes", f).unwrap();
bf.write_all(bw).unwrap();
}
{
let f = OpenOptions::new().create(true)
.read(true).write(true).open(path).unwrap();
let mut bf = BufFile::new("tes", f).unwrap();
let mut br = vec![0u8; bw.len()];
bf.read_exact(&mut br).unwrap();
assert_eq!(&br, bw);
}
Changelogs
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.