rust-cli-test 0.1.0

A simple test RUST cli app
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::prelude::*;
use std::path::Path;

pub fn file_size(path: &Path) -> crate::Result<u64> {
    path.metadata().map(|meta| meta.len()).wrap()
}

pub fn human_readable_file_size(path: &Path, format: &str) -> crate::Result<String> {
    let format = format.trim().to_lowercase();
    file_size(path).map(|size| {
        if format == "kb" {
            format!("{}", size / 1024)
        } else {
            format!("{}", size)
        }
    })
}