get-file-size

Crates.ioget-file-size
lib.rsget-file-size
version0.1.2
created_at2025-02-09 03:18:04.195103+00
updated_at2025-07-12 22:43:43.324048+00
descriptionRust crate for asynchronous file size retrieval and line counting, utilizing the tokio runtime for non-blocking I/O operations.
homepage
repositoryhttps://github.com/klebs6/klebs-general
max_upload_size
id1548619
size33,024
(klebs6)

documentation

README

get-file-size

get-file-size is a Rust crate for efficiently determining the size of a file and counting the number of lines within a file asynchronously. This utility is particularly useful in systems where I/O operations need to be non-blocking, elevating performance in concurrent applications or environments where swift, streamlined file operations are essential.

Features

  • Asynchronous File Size Retrieval: Implement utilizing the GetFileSize trait, which employs asynchronous methods to fetch file metadata, ensuring minimal blocking during operations.

  • Line Counting: An additional function, count_lines_in_file, provides the ability to count lines in a file asynchronously.

Usage

Integrate get-file-size into your project by adding it as a dependency in your Cargo.toml:

[dependencies]
get-file-size = "0.1.0"

Example

use get_file_size::GetFileSize;
use std::path::PathBuf;
use tokio;

#[tokio::main]
async fn main() -> Result<(), get_file_size::FileError> {
    let file_path = PathBuf::from("example.txt");

    // Obtain file size asynchronously
    let file_size = file_path.file_size().await?;
    println!("File size: {} bytes", file_size);

    // Count lines in file asynchronously
    let line_count = get_file_size::count_lines_in_file(&file_path).await?;
    println!("Line count: {}", line_count);

    Ok(())
}

Contributing

Contributions, bug reports, and feature requests are welcome. Please check the issues page to get involved.

License

This project is dual-licensed under the terms of the MIT license and the Apache License (Version 2.0).

Commit count: 634

cargo fmt