#buffer #io

rabuf

randome access buffer for io

15 releases

Uses new Rust 2021

0.1.15 Jun 13, 2022
0.1.14 Feb 19, 2022
0.1.12 Jan 25, 2022
0.1.6 Dec 19, 2021
0.1.3 Nov 26, 2021

#45 in Memory management

Download history 3/week @ 2022-03-06 60/week @ 2022-03-13 44/week @ 2022-03-20 2/week @ 2022-03-27 18/week @ 2022-04-03 3/week @ 2022-04-10 2/week @ 2022-04-17 46/week @ 2022-04-24 74/week @ 2022-05-01 88/week @ 2022-05-08 241/week @ 2022-05-15 60/week @ 2022-05-22 102/week @ 2022-05-29 72/week @ 2022-06-05 31/week @ 2022-06-12 11/week @ 2022-06-19

231 downloads per month
Used in siamesedb

MIT/Apache

69KB
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

This crate's changelog here.

License

This project is licensed under either of

at your option.

No runtime deps

Features

  • buf_auto_buf_size
  • buf_debug
  • buf_hash_turbo
  • buf_lru
  • buf_myhash
  • buf_overf_rem
  • buf_overf_rem_all
  • buf_overf_rem_half
  • buf_pin_zero
  • buf_print_hits
  • buf_stats