/* * Copyright (c) 2022, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #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; }; [[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 RefCounted , public Weakable , public Bindings::Wrappable { public: using WrapperType = Bindings::BlobWrapper; Blob(ByteBuffer byte_buffer, String type); virtual ~Blob() override; static DOM::ExceptionOr> create(Optional> const& blob_parts = {}, Optional const& options = {}); 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(ByteBuffer byte_buffer); private: Blob() = default; ByteBuffer m_byte_buffer {}; String m_type {}; }; }