Struct file_ext::FileExt

source ·
pub struct FileExt;

Implementations§

Returns portion of a file of specified range. Range described as starting from byte M up to byte N.

Examples
use file_ext::FileExt;
#[test]
fn partial_read() {
    let path = "test/index.html";
    let file_raw_bytes = FileExt::read_file_partially(path, 4, 10).unwrap();
    let content = String::from_utf8(file_raw_bytes).unwrap();

    let expected_content = "CTYPE h";

    assert_eq!(expected_content, content);
}

Returns file content

Examples
use file_ext::FileExt;
#[test]
fn file_content() {
    let path = "test/index.html";
    let file_raw_bytes = FileExt::read_file(path).unwrap();
    let content = String::from_utf8(file_raw_bytes).unwrap();

    let expected_content = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Title</title>\n</head>\n<body>\n\n</body>\n</html>";

    assert_eq!(expected_content, content);
}

Returns file modification timestamp as nanoseconds in Unix epoch

Will return absolute file path

Will try to read from file. If file does not exist, will create and write to it given byte array

Will create a file on the path

Returns boolean indicating file existence on the path

Examples
use file_ext::FileExt;
#[test]
fn file_exists() {
    let path = "test/index_rewrite";
    let exists = FileExt::does_file_exist(path);
    assert!(exists);
}

Will write given byte array to a file on the path

Checks if the file is symlink

Examples
use file_ext::FileExt;
#[test]
fn link_points_to() {
    let path = "test/index_rewrite";
    let is_symlink = FileExt::is_symlink(path).unwrap();
    assert!(is_symlink);
}

Returns path to a file, symlink points to

Examples
use file_ext::FileExt;
#[test]
fn link_points_to() {
    let path = "test/index_rewrite";
    let points_to = FileExt::symlink_points_to(path).unwrap();
    assert_eq!("index.html", points_to);
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.