#chunk #file #chunking #process-file #concurrency

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

#996 in Filesystem

Download history 96/week @ 2024-03-14 32/week @ 2024-03-21 72/week @ 2024-03-28 45/week @ 2024-04-04 43/week @ 2024-04-11 62/week @ 2024-04-18 68/week @ 2024-04-25 83/week @ 2024-05-02 55/week @ 2024-05-09 111/week @ 2024-05-16 156/week @ 2024-05-23 82/week @ 2024-05-30 114/week @ 2024-06-06 127/week @ 2024-06-13 116/week @ 2024-06-20 153/week @ 2024-06-27

526 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

~295KB