rabuf

Crates.iorabuf
lib.rsrabuf
version0.1.20
sourcesrc
created_at2021-11-11 13:06:45.199499
updated_at2024-06-09 11:40:34.999339
descriptionrandome access buffer for io
homepage
repositoryhttps://github.com/aki-akaguma/rabuf
max_upload_size
id480155
size97,160
(aki-akaguma)

documentation

README

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.

Commit count: 44

cargo fmt