Crates.io | ape-fatfs |
lib.rs | ape-fatfs |
version | 0.2.0 |
source | src |
created_at | 2023-04-22 02:41:58.294415 |
updated_at | 2023-05-17 19:54:50.533083 |
description | versitile FAT library for embedded systems |
homepage | |
repository | https://github.com/Gip-Gip/ape-fatfs |
max_upload_size | |
id | 845785 |
size | 295,798 |
This crate is can be used by adding fatfs
to the dependencies in your
project's Cargo.toml
.
[dependencies]
ape-fatfs = "0.2.0"
# Comment out the above and uncomment the below to enable no_std support
# ape-fatfs = { default_features = false, version = 0.2.0 }
use std::io::prelude::*;
use ape_fatfs::{
fs::{
FsOptions,
FileSystem,
}
};
fn main() {
# std::fs::copy("resources/fat16.img", "fat.img").unwrap();
// 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());
}
# std::fs::remove_file("fat.img").unwrap();
}