pub struct File { /* private fields */ }
Expand description
A File
.
Implementations
sourceimpl File
impl File
sourcepub fn new<T>(name: &str, contents: T) -> File where
T: BlobContents,
pub fn new<T>(name: &str, contents: T) -> File where
T: BlobContents,
Create a new File
with the given name and contents.
contents
can be &str
, &[u8]
, or js_sys::ArrayBuffer
.
sourcepub 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"));
sourcepub fn last_modified_time(&self) -> SystemTime
pub fn last_modified_time(&self) -> SystemTime
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>
Trait Implementations
impl StructuralPartialEq for File
Auto Trait Implementations
impl RefUnwindSafe for File
impl !Send for File
impl !Sync for File
impl Unpin for File
impl UnwindSafe for File
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more