pub struct File { /* private fields */ }
Expand description
A File
.
Implementations§
source§impl File
impl File
sourcepub fn new<T>(name: &str, contents: T) -> Filewhere
T: BlobContents,
pub fn new<T>(name: &str, contents: T) -> Filewhere 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>
) -> Filewhere
T: BlobContents,
pub fn new_with_options<T>( name: &str, contents: T, mime_type: Option<&str>, last_modified_time: Option<SystemTime> ) -> Filewhere 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>§
pub fn slice(&self, start: u64, end: u64) -> Self
sourcepub fn raw_mime_type(&self) -> String
pub fn raw_mime_type(&self) -> String
The raw MIME type (also known as content type or media type) of the File
or
Blob
.
Trait Implementations§
source§impl PartialEq<File> for File
impl PartialEq<File> for File
impl Eq for File
impl StructuralEq for File
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more