kinode-dao / process_lib

Standard Library crate for Kinode processes written in Rust
Apache License 2.0
3 stars 2 forks source link

vfs helpers #16

Closed bitful-pannul closed 9 months ago

bitful-pannul commented 9 months ago

some impl functions!

perhaps now I can remove some of the "helper" actions in vfs, like ReadAt, and just let users do what they would've done with std::fs anyway but with our std_lib, that is call .seek() and then .write()

examples of usage of a file:

let drive = create_drive(our.package_id(), "testing")?;

let test_file = format!("{}/test.txt", path);

// open/create and write file
let mut file = open_file(path, true)?;
let bytestring = message.into_bytes();

file.write(&bytestring)?; // "yes hello"

// different action, can open again, seek to start etc, read into buffer len:

let mut buffer = vec![0; 3];
file.read(&mut buffer)?;

let string = String::from_utf8(buffer)?;
println!("vfstester: read {:?}", string); // "yes"

full test lib.rs: https://gist.github.com/bitful-pannul/b7cbdaafaef9b9056794d2c20507ce21