Crates.io | rabuf |
lib.rs | rabuf |
version | 0.1.20 |
source | src |
created_at | 2021-11-11 13:06:45.199499 |
updated_at | 2024-06-09 11:40:34.999339 |
description | randome access buffer for io |
homepage | |
repository | https://github.com/aki-akaguma/rabuf |
max_upload_size | |
id | 480155 |
size | 97,160 |
The Buffer for random access file.
When you read and write a file,
this read and write in Chunk
units and reduce IO operation.
Chunk
units os io operationuse 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);
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);
}
This project is licensed under either of
at your option.