pub struct File { /* private fields */ }
Expand description
A File
.
Implementations
Create a new File
with the given name and contents.
contents
can be &str
, &[u8]
, or js_sys::ArrayBuffer
.
pub fn new_with_options<T>(
name: &str,
contents: T,
mime_type: Option<&str>,
last_modified_time: Option<SystemTime>
) -> File where
T: BlobContents,
pub fn new_with_options<T>(
name: &str,
contents: T,
mime_type: Option<&str>,
last_modified_time: Option<SystemTime>
) -> File where
T: BlobContents,
Like File::new
, but allows customizing the MIME type (also
known as content type or media type), and the last modified time.
std::time::SystemTime
is a low level type, use a crate like
chrono
to work with a more user-friendly
representation of time.
Examples
use chrono::prelude::*;
use gloo_file::File;
// Just create a dummy `gloo::file::File` for demonstration purposes.
let example_file = File::new_with_options(
"motivation.txt",
"live your best life",
Some("text/plain"),
Some(Utc::now().into())
);
assert_eq!(example_file.name(), String::from("motivation.txt"));
assert_eq!(example_file.raw_mime_type(), String::from("text/plain"));
Gets the time that the file was last modified.
std::time::SystemTime
is a low level type, use a crate like
chrono
to work with more user-friendly
representations of time. For example:
use chrono::prelude::*;
use gloo_file::File;
// Just create a dummy `gloo::file::File` for demonstration purposes.
let example_file = File::new("test_file.txt", "<almost empty contents>");
let date: DateTime<Utc> = example_file.last_modified_time().into();
Methods from Deref<Target = Blob>
The raw MIME type (also known as content type or media type) of the File
or
Blob
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for File
impl UnwindSafe for File
Blanket Implementations
Mutably borrows from an owned value. Read more