pub struct PickedFile { /* private fields */ }Expand description
One file or folder the user chose, to read and write.
Cheap to clone: a clone names the same file. See the module documentation for what it holds on each platform.
Implementations§
Source§impl PickedFile
impl PickedFile
Sourcepub const MAX_READ_BYTES: u64
pub const MAX_READ_BYTES: u64
The longest file PickedFile::read reads, in bytes. A longer one is
FileError::TooLarge before anything is read.
Sourcepub fn from_path(path: impl Into<String>) -> PickedFile
pub fn from_path(path: impl Into<String>) -> PickedFile
A file by its path, without a dialog. For a path the application already had, such as one it saved in its own storage last time.
Only where there are paths: a browser gives a page none, so there is nothing to make one from there.
Sourcepub fn path(&self) -> Option<&str>
pub fn path(&self) -> Option<&str>
The file’s absolute path, where there is one. Never in a browser.
Sourcepub fn is_folder(&self) -> bool
pub fn is_folder(&self) -> bool
Whether this is a folder.
For a path, the file system is asked the first time, which is one small call on the calling thread. A browser said so when it handed the file over.
Sourcepub fn delivery(&self) -> Delivery
pub fn delivery(&self) -> Delivery
How the file reached the application. Always Delivery::Handle for a path.
Sourcepub fn can_write_again(&self) -> bool
pub fn can_write_again(&self) -> bool
Whether a write changes this same file again: a Delivery::Handle that is not a
folder. When it is false the next save is a “save as”.
Sourcepub async fn write(&self, bytes: impl Into<Vec<u8>>) -> Result<(), FileError>
pub async fn write(&self, bytes: impl Into<Vec<u8>>) -> Result<(), FileError>
Replaces the file’s contents with bytes.
For a path the new contents go to a temporary file in the same folder, which is then
renamed over the file, so the file is always either what it was or what was written.
A browser does the same inside the File System Access API’s writable stream. On a
Delivery::Download every write is a new download of bytes under the file’s name.
Sourcepub async fn entries(&self) -> Result<Vec<PickedFile>, FileError>
pub async fn entries(&self) -> Result<Vec<PickedFile>, FileError>
What a folder holds directly, files and folders both, in name order for a path and in the browser’s order in a browser.
Sourcepub async fn child(
&self,
name: &str,
create: bool,
) -> Result<PickedFile, FileError>
pub async fn child( &self, name: &str, create: bool, ) -> Result<PickedFile, FileError>
The file or folder called name directly inside this folder. With create, a file of
that name is made, empty, when there is none.
name is one name: one with a path separator in it, or . or .., is refused before
anything is asked.