| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |  * Copyright (c) 2022-2023, Kenneth Myhra <kennethmyhra@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/NonnullRefPtr.h>
 | 
					
						
							|  |  |  | #include <AK/Vector.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | #include <LibWeb/Bindings/BlobPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-04 11:44:38 +02:00
										 |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  | #include <LibWeb/WebIDL/ExceptionOr.h>
 | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::FileAPI { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  | using BlobPart = Variant<JS::Handle<JS::Object>, JS::Handle<Blob>, String>; | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct BlobPropertyBag { | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |     String type = String {}; | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  |     Bindings::EndingType endings; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  | [[nodiscard]] ErrorOr<String> convert_line_endings_to_native(StringView string); | 
					
						
							| 
									
										
										
										
											2022-07-30 10:36:18 +02:00
										 |  |  | [[nodiscard]] ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optional<BlobPropertyBag> const& options = {}); | 
					
						
							| 
									
										
										
										
											2022-08-01 19:33:27 +02:00
										 |  |  | [[nodiscard]] bool is_basic_latin(StringView view); | 
					
						
							| 
									
										
										
										
											2022-07-24 16:05:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-04 11:44:38 +02:00
										 |  |  | class Blob : public Bindings::PlatformObject { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(Blob, Bindings::PlatformObject); | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     virtual ~Blob() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> create(JS::Realm&, ByteBuffer, String type); | 
					
						
							| 
									
										
										
										
											2022-09-25 18:08:29 -06:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> create(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {}); | 
					
						
							|  |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> construct_impl(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {}); | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-25 23:08:55 +02:00
										 |  |  |     // https://w3c.github.io/FileAPI/#dfn-size
 | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  |     u64 size() const { return m_byte_buffer.size(); } | 
					
						
							| 
									
										
										
										
											2022-07-25 23:08:55 +02:00
										 |  |  |     // https://w3c.github.io/FileAPI/#dfn-type
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |     String const& type() const { return m_type; } | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |     WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {}); | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |     WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> text(); | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  |     JS::Promise* array_buffer(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-24 15:43:33 +02:00
										 |  |  |     ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-24 21:32:18 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |     Blob(JS::Realm&, ByteBuffer, String type); | 
					
						
							| 
									
										
										
										
											2022-09-25 18:08:29 -06:00
										 |  |  |     Blob(JS::Realm&, ByteBuffer); | 
					
						
							| 
									
										
										
										
											2022-07-24 21:32:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-28 12:33:35 -05:00
										 |  |  |     virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-06-13 07:31:06 +12:00
										 |  |  |     WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> get_stream(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 18:08:29 -06:00
										 |  |  |     explicit Blob(JS::Realm&); | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ByteBuffer m_byte_buffer {}; | 
					
						
							| 
									
										
										
										
											2023-02-25 10:27:38 +01:00
										 |  |  |     String m_type {}; | 
					
						
							| 
									
										
										
										
											2022-07-10 18:31:17 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |