|
|
@ -123,6 +123,9 @@ pub struct Archive { |
|
|
|
/// Create a new file and write bytes to it:
|
|
|
|
/// Create a new file and write bytes to it:
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// ```no_run
|
|
|
|
|
|
|
|
/// # use std::error::Error;
|
|
|
|
|
|
|
|
/// # fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
|
|
|
/// #
|
|
|
|
/// use std::io::prelude::*;
|
|
|
|
/// use std::io::prelude::*;
|
|
|
|
/// use ctru::services::fs::{Fs, File};
|
|
|
|
/// use ctru::services::fs::{Fs, File};
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -131,11 +134,17 @@ pub struct Archive { |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// let mut file = File::create(&sdmc, "/foo.txt")?;
|
|
|
|
/// let mut file = File::create(&sdmc, "/foo.txt")?;
|
|
|
|
/// file.write_all(b"Hello, world!")?;
|
|
|
|
/// file.write_all(b"Hello, world!")?;
|
|
|
|
|
|
|
|
/// #
|
|
|
|
|
|
|
|
/// # Ok(())
|
|
|
|
|
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Read the contents of a file into a `String`::
|
|
|
|
/// Read the contents of a file into a `String`::
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// ```no_run
|
|
|
|
|
|
|
|
/// # use std::error::Error;
|
|
|
|
|
|
|
|
/// # fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
|
|
|
/// #
|
|
|
|
/// use std::io::prelude::*;
|
|
|
|
/// use std::io::prelude::*;
|
|
|
|
/// use ctru::services::fs::{Fs, File};
|
|
|
|
/// use ctru::services::fs::{Fs, File};
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -146,12 +155,18 @@ pub struct Archive { |
|
|
|
/// let mut contents = String::new();
|
|
|
|
/// let mut contents = String::new();
|
|
|
|
/// file.read_to_string(&mut contents)?;
|
|
|
|
/// file.read_to_string(&mut contents)?;
|
|
|
|
/// assert_eq!(contents, "Hello, world!");
|
|
|
|
/// assert_eq!(contents, "Hello, world!");
|
|
|
|
|
|
|
|
/// #
|
|
|
|
|
|
|
|
/// # Ok(())
|
|
|
|
|
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// It can be more efficient to read the contents of a file with a buffered
|
|
|
|
/// It can be more efficient to read the contents of a file with a buffered
|
|
|
|
/// `Read`er. This can be accomplished with `BufReader<R>`:
|
|
|
|
/// `Read`er. This can be accomplished with `BufReader<R>`:
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// ```no_run
|
|
|
|
|
|
|
|
/// # use std::error::Error;
|
|
|
|
|
|
|
|
/// # fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
|
|
|
/// #
|
|
|
|
/// use std::io::BufReader;
|
|
|
|
/// use std::io::BufReader;
|
|
|
|
/// use std::io::prelude::*;
|
|
|
|
/// use std::io::prelude::*;
|
|
|
|
/// use ctru::services::fs::{Fs, File};
|
|
|
|
/// use ctru::services::fs::{Fs, File};
|
|
|
@ -164,6 +179,9 @@ pub struct Archive { |
|
|
|
/// let mut contents = String::new();
|
|
|
|
/// let mut contents = String::new();
|
|
|
|
/// buf_reader.read_to_string(&mut contents)?;
|
|
|
|
/// buf_reader.read_to_string(&mut contents)?;
|
|
|
|
/// assert_eq!(contents, "Hello, world!");
|
|
|
|
/// assert_eq!(contents, "Hello, world!");
|
|
|
|
|
|
|
|
/// #
|
|
|
|
|
|
|
|
/// # Ok(())
|
|
|
|
|
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
pub struct File { |
|
|
|
pub struct File { |
|
|
|
handle: u32, |
|
|
|
handle: u32, |
|
|
|