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

Download history 1/week @ 2024-08-20 11/week @ 2024-08-27 2/week @ 2024-09-17 39/week @ 2024-09-24 4/week @ 2024-10-01

1,076 downloads per month
Used in 2 crates

MIT/Apache

72KB
1.5K SLoC

rabuf

crate Docs Rust Version Apache2/MIT licensed Test ubu Test mac Test win

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