#data-stream #reverse #buf-reader #byte-stream #order #byte-reader #buffered

rev_buf_reader

Crate that provides a buffered reader capable of reading chunks of bytes of a data stream in reverse order. Its implementation is an adapted copy of BufReader from the nightly std::io.

4 releases (2 breaking)

0.3.0 Jan 31, 2022
0.2.0 Feb 1, 2020
0.1.1 May 12, 2019
0.1.0 Mar 14, 2019

#1073 in Algorithms

Download history 1499/week @ 2024-08-04 1732/week @ 2024-08-11 1699/week @ 2024-08-18 1578/week @ 2024-08-25 1396/week @ 2024-09-01 1610/week @ 2024-09-08 1545/week @ 2024-09-15 2837/week @ 2024-09-22 2439/week @ 2024-09-29 1635/week @ 2024-10-06 2504/week @ 2024-10-13 2958/week @ 2024-10-20 2700/week @ 2024-10-27 2626/week @ 2024-11-03 2354/week @ 2024-11-10 2235/week @ 2024-11-17

10,304 downloads per month
Used in 11 crates (10 directly)

Apache-2.0 OR MIT

33KB
475 lines

rev_buf_reader

GitHub Actions Workflow docs license Crates.io

This Rust crate provides a buffered reader capable of reading chunks of bytes of a data stream in reverse order. Its implementation is an adapted copy of BufReader from the nightly std::io.

Usage

Reading chunks of bytes in reverse order:

extern crate rev_buf_reader;

use rev_buf_reader::RevBufReader;
use std::io::{self, Read};

let data = [0, 1, 2, 3, 4, 5, 6, 7];
let inner = io::Cursor::new(&data);
let mut reader = RevBufReader::new(inner);

let mut buffer = [0, 0, 0];
assert_eq!(reader.read(&mut buffer).ok(), Some(3));
assert_eq!(buffer, [5, 6, 7]);

let mut buffer = [0, 0, 0, 0, 0];
assert_eq!(reader.read(&mut buffer).ok(), Some(5));
assert_eq!(buffer, [0, 1, 2, 3, 4]);

Reading text lines in reverse order:

extern crate rev_buf_reader;

use rev_buf_reader::RevBufReader;
use std::io::{self, BufRead};

let data = "This\nis\na sentence";
let inner = io::Cursor::new(&data);
let reader = RevBufReader::new(inner);
let mut lines = reader.lines();

assert_eq!(lines.next().unwrap().unwrap(), "a sentence".to_string());
assert_eq!(lines.next().unwrap().unwrap(), "is".to_string());
assert_eq!(lines.next().unwrap().unwrap(), "This".to_string());
assert!(lines.next().is_none());

Features

rev_buf_reader has one feature: read_initializer, which corresponds to an experimental feature of nightly Rust. If you use it in your project by adding #![feature(read_initializer)], you'll need to enable it for rev_buf_reader as well in your Cargo.toml.

Dependencies

~250KB