/* * Copyright (c) 2022, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace Web::FileAPI { using BlobPart = Variant, NonnullRefPtr, String>; struct BlobPropertyBag { String type = String::empty(); Bindings::EndingType endings; }; class Blob : public RefCounted , public Weakable , public Bindings::Wrappable { public: using WrapperType = Bindings::BlobWrapper; Blob(ByteBuffer byte_buffer, String type); static DOM::ExceptionOr> create(Optional> const& blob_parts = {}, Optional const& options = {}); static DOM::ExceptionOr> create_with_global_object(Bindings::WindowObject&, Optional> const& blob_parts = {}, Optional const& options = {}); u64 size() const { return m_byte_buffer.size(); } String type() const& { return m_type; } DOM::ExceptionOr> slice(Optional start = {}, Optional end = {}, Optional const& content_type = {}); JS::Promise* text(); JS::Promise* array_buffer(); virtual JS::Object* create_wrapper(JS::GlobalObject&); private: Blob() = default; static ErrorOr process_blob_parts(Vector const& blob_parts); ByteBuffer m_byte_buffer {}; String m_type {}; friend class XHR::XMLHttpRequest; }; }