use super::*;
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Blob {
inner: Any,
}
impl FromVal for Blob {
fn from_val(v: &Any) -> Self {
Blob {
inner: Any::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 Blob {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for Blob {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for Blob {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for Blob {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<Blob> for Any {
fn from(s: Blob) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&Blob> for Any {
fn from(s: &Blob) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(Blob);
impl Blob {
pub fn size(&self) -> u64 {
self.inner.get("size").as_::<u64>()
}
}
impl Blob {
pub fn type_(&self) -> JsString {
self.inner.get("type").as_::<JsString>()
}
}
impl Blob {
pub fn new() -> Blob {
Self {
inner: Any::global("Blob").new(&[]).as_::<Any>(),
}
}
}
impl Blob {
pub fn new_with_blob_parts(blob_parts: &TypedArray<Any>) -> Blob {
Self {
inner: Any::global("Blob").new(&[blob_parts.into()]).as_::<Any>(),
}
}
}
impl Blob {
pub fn new_with_blob_parts_and_options(
blob_parts: &TypedArray<Any>,
options: &BlobPropertyBag,
) -> Blob {
Self {
inner: Any::global("Blob")
.new(&[blob_parts.into(), options.into()])
.as_::<Any>(),
}
}
}
impl Blob {
pub fn slice(&self) -> Blob {
self.inner.call("slice", &[]).as_::<Blob>()
}
}
impl Blob {
pub fn slice_with_start(&self, start: i64) -> Blob {
self.inner.call("slice", &[start.into()]).as_::<Blob>()
}
}
impl Blob {
pub fn slice_with_start_and_end(&self, start: i64, end: i64) -> Blob {
self.inner
.call("slice", &[start.into(), end.into()])
.as_::<Blob>()
}
}
impl Blob {
pub fn slice_with_start_and_end_and_content_type(
&self,
start: i64,
end: i64,
content_type: &JsString,
) -> Blob {
self.inner
.call("slice", &[start.into(), end.into(), content_type.into()])
.as_::<Blob>()
}
}
impl Blob {
pub fn stream(&self) -> ReadableStream {
self.inner.call("stream", &[]).as_::<ReadableStream>()
}
}
impl Blob {
pub fn text(&self) -> Promise<JsString> {
self.inner.call("text", &[]).as_::<Promise<JsString>>()
}
}
impl Blob {
pub fn array_buffer(&self) -> Promise<ArrayBuffer> {
self.inner
.call("arrayBuffer", &[])
.as_::<Promise<ArrayBuffer>>()
}
}
impl Blob {
pub fn bytes(&self) -> Promise<Uint8Array> {
self.inner.call("bytes", &[]).as_::<Promise<Uint8Array>>()
}
}