#chunk #file

file-chunker

Efficiently process a file in (approximately) equally-sized parts

2 releases

0.1.1 Feb 10, 2022
0.1.0 Feb 9, 2022

#1028 in Filesystem

Download history 151/week @ 2024-07-20 79/week @ 2024-07-27 110/week @ 2024-08-03 247/week @ 2024-08-10 148/week @ 2024-08-17 167/week @ 2024-08-24 200/week @ 2024-08-31 108/week @ 2024-09-07 110/week @ 2024-09-14 92/week @ 2024-09-21 163/week @ 2024-09-28 1256/week @ 2024-10-05 292/week @ 2024-10-12 256/week @ 2024-10-19 100/week @ 2024-10-26 157/week @ 2024-11-02

955 downloads per month
Used in krapslog

MIT license

17KB
222 lines

file-chunker

This crate provides the FileChunker type, which is useful for efficiently reading a file in (approximately) equally-sized parts.

The original use case was to process a log file in chunks, one thread per chunk, and to guarantee that each chunk ended with a full line of text.

Example

use file_chunker::FileChunker;
let file = std::fs::File::open("/path/to/file").unwrap();
let chunker = FileChunker::new(&file).unwrap();
chunker.chunks(1024, Some('\n'))
    .unwrap()
    .iter()
    .for_each(|chunk| {
        println!("{:?}", chunk);
    });

lib.rs:

This crate provides the FileChunker type, which is useful for efficiently reading a file in (approximately) equally-sized parts.

The original use case was to process a log file in chunks, one thread per chunk, and to guarantee that each chunk ended with a full line of text.

Example

use file_chunker::FileChunker;

let file = std::fs::File::open("/path/to/file").unwrap();
let chunker = FileChunker::new(&file).unwrap();
chunker.chunks(1024, Some('\n'))
    .unwrap()
    .iter()
    .for_each(|chunk| {
        println!("{:?}", chunk);
    });

Dependencies

~300KB