Struct playdate_fs::file::File
source · pub struct File(/* private fields */);Implementations§
source§impl File
impl File
pub fn valid(&self) -> bool
sourcepub fn open<P: AsRef<Path>>(path: P, data_dir: bool) -> Result<File, ApiError>
pub fn open<P: AsRef<Path>>(path: P, data_dir: bool) -> Result<File, ApiError>
Attempts to open a file in read-only mode.
See the OpenOptions::open method for more details.
https://sdk.play.date/2.0.1/Inside%20Playdate%20with%20C.html#f-file.open
sourcepub fn read(
&mut self,
to: &mut Vec<u8>,
len: c_uint
) -> Result<c_uint, ApiError>
pub fn read( &mut self, to: &mut Vec<u8>, len: c_uint ) -> Result<c_uint, ApiError>
Reads up to len bytes from the file into the buffer buf.
Returns the number of bytes read (0 indicating end of file).
Examples found in repository?
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn read_file() -> Result<(), fs::error::ApiError> {
let fs = fs::Fs::new()?;
println!("reading file metadata");
let info = fs.metadata(&FILE)?;
println!("info: {info:?}");
// prepare prefilled buffer:
println!("preparing buffer for {} bytes", info.size);
let mut buf = vec![0_u8; info.size as usize];
let mut file = FileOptions::new().read(true)
.read_data(true)
.open_using(FILE, &fs)?;
println!("reading '{FILE}'");
let bytes_read = file.read(&mut buf, info.size)?;
println!("read {bytes_read} bytes");
let result = String::from_utf8(buf)?;
println!("content:\n{result}");
Ok(())
}sourcepub fn write(&mut self, from: &[u8]) -> Result<c_uint, ApiError>
pub fn write(&mut self, from: &[u8]) -> Result<c_uint, ApiError>
Writes the buffer of bytes buf to the file. Returns the number of bytes written.
sourcepub fn flush(&mut self) -> Result<c_uint, ApiError>
pub fn flush(&mut self) -> Result<c_uint, ApiError>
Flushes the output buffer of file immediately. Returns the number of bytes written.
sourcepub fn tell(&mut self) -> Result<c_uint, ApiError>
pub fn tell(&mut self) -> Result<c_uint, ApiError>
Returns the current read/write offset in the given file handle.
sourcepub fn seek(&mut self, pos: SeekFrom) -> Result<c_uint, ApiError>
pub fn seek(&mut self, pos: SeekFrom) -> Result<c_uint, ApiError>
Sets the read/write offset in the given file handle to pos, relative to the whence.
Whence::Set is relative to the beginning of the file,
Whence::Cur is relative to the current position of the file pointer, and
Whence::End is relative to the end of the file.
Returns 0 on success.
sourcepub fn options() -> impl OpenOptions + FileOptionsExt
pub fn options() -> impl OpenOptions + FileOptionsExt
Creates a blank new set of options ready for configuration. All options are initially set to false.
It is equivalent to FileOptions::new().