use super::*;
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct File {
inner: Blob,
}
impl FromVal for File {
fn from_val(v: &Any) -> Self {
File {
inner: Blob::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for File {
type Target = Blob;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for File {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for File {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for File {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<File> for Any {
fn from(s: File) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&File> for Any {
fn from(s: &File) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(File);
impl File {
pub fn name(&self) -> JsString {
self.inner.get("name").as_::<JsString>()
}
}
impl File {
pub fn last_modified(&self) -> i64 {
self.inner.get("lastModified").as_::<i64>()
}
}
impl File {
pub fn webkit_relative_path(&self) -> JsString {
self.inner.get("webkitRelativePath").as_::<JsString>()
}
}
impl File {
pub fn new(file_bits: &TypedArray<Any>, file_name: &JsString) -> File {
Self {
inner: Any::global("File")
.new(&[file_bits.into(), file_name.into()])
.as_::<Blob>(),
}
}
}
impl File {
pub fn new_with_options(
file_bits: &TypedArray<Any>,
file_name: &JsString,
options: &FilePropertyBag,
) -> File {
Self {
inner: Any::global("File")
.new(&[file_bits.into(), file_name.into(), options.into()])
.as_::<Blob>(),
}
}
}