/* * 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, DeprecatedString>; struct BlobPropertyBag { DeprecatedString type = DeprecatedString::empty(); Bindings::EndingType endings; }; [[nodiscard]] ErrorOr convert_line_endings_to_native(DeprecatedString 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 JS::NonnullGCPtr create(JS::Realm&, ByteBuffer, DeprecatedString 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 DeprecatedString const& type() const { return m_type; } WebIDL::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(JS::Realm&, ByteBuffer, DeprecatedString type); Blob(JS::Realm&, ByteBuffer); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; private: explicit Blob(JS::Realm&); ByteBuffer m_byte_buffer {}; DeprecatedString m_type {}; }; }