/* * Copyright (c) 2022, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::FileAPI { using BlobPart = Variant, JS::Handle, String>; struct BlobPropertyBag { String type = String::empty(); Bindings::EndingType endings; }; [[nodiscard]] ErrorOr convert_line_endings_to_native(String const& string); [[nodiscard]] ErrorOr process_blob_parts(Vector const& blob_parts, Optional const& options = {}); [[nodiscard]] bool is_basic_latin(StringView view); class Blob : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Blob, Bindings::PlatformObject); public: virtual ~Blob() override; static DOM::ExceptionOr> create(HTML::Window&, Optional> const& blob_parts = {}, Optional const& options = {}); static DOM::ExceptionOr> create(HTML::Window&, ByteBuffer, String type); static DOM::ExceptionOr> create_with_global_object(HTML::Window&, Optional> const& blob_parts = {}, Optional const& options = {}); // https://w3c.github.io/FileAPI/#dfn-size u64 size() const { return m_byte_buffer.size(); } // https://w3c.github.io/FileAPI/#dfn-type String const& type() const { return m_type; } DOM::ExceptionOr> slice(Optional start = {}, Optional end = {}, Optional const& content_type = {}); JS::Promise* text(); JS::Promise* array_buffer(); ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); } protected: Blob(HTML::Window&, ByteBuffer, String type); Blob(HTML::Window&, ByteBuffer); private: explicit Blob(HTML::Window&); ByteBuffer m_byte_buffer {}; String m_type {}; }; } WRAPPER_HACK(Blob, Web::FileAPI)