/* * Copyright (c) 2022-2023, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::FileAPI { using BlobPart = Variant, JS::Handle, String>; struct BlobPropertyBag { String type = String {}; Bindings::EndingType endings; }; [[nodiscard]] ErrorOr convert_line_endings_to_native(StringView 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 WebIDL::ExceptionOr> create(JS::Realm&, ByteBuffer, String type); static WebIDL::ExceptionOr> create(JS::Realm&, Optional> const& blob_parts = {}, Optional const& options = {}); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, 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; } WebIDL::ExceptionOr> slice(Optional start = {}, Optional end = {}, Optional const& content_type = {}); WebIDL::ExceptionOr> text(); JS::Promise* array_buffer(); ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); } protected: Blob(JS::Realm&, ByteBuffer, String type); Blob(JS::Realm&, ByteBuffer); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; private: explicit Blob(JS::Realm&); ByteBuffer m_byte_buffer {}; String m_type {}; }; }