Expand description
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);
}
Re-exports§
pub use maybe::MaybeSlice;
Modules§
Structs§
- Generic random access buffer.
Traits§
- Truncates or extends the underlying file.
- File syncronization include OS-internal metadata to disk.
- Read small bytes less than chunk size.
- Write small bytes less than chunk size.
Functions§
- Round up power of 2.
Type Aliases§
- Buffered File for ramdom access.