Crate ape_fatfs

source ·
Expand description

MIT License Crates.io Documentation APE

versitile FAT library for embedded systems

Usage

This crate is can be used by adding fatfs to the dependencies in your project’s Cargo.toml.

[dependencies]
ape-fatfs = "0.1.0"
# Comment out the above and uncomment the below to enable no_std support
# ape-fatfs = { default_features = false, version = 0.1.0 }

Examples

use std::io::prelude::*;
use ape_fatfs::{
    fs::{
        FsOptions,
        FileSystem,
    }
};

fn main() {
    // Initialize a filesystem object
    let img_file = std::fs::OpenOptions::new().read(true).write(true)
        .open("fat.img").unwrap();
    let buf_stream = fscommon::BufStream::new(img_file);
    let fs = FileSystem::new(buf_stream, FsOptions::new()).unwrap();
    let root_dir = fs.root_dir();

    // Write a file
    root_dir.create_dir("foo").unwrap();
    let mut file = root_dir.create_file("foo/hello.txt").unwrap();
    file.truncate().unwrap();
    file.write_all(b"Hello World!").unwrap();

    // Read a directory
    let dir = root_dir.open_dir("foo").unwrap();
    for r in dir.iter() {
        let entry = r.unwrap();
        println!("{}", entry.file_name());
    }
}

Modules

Macros