mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 02:42:44 +00:00 
			
		
		
		
	AK: Move Stream and SeekableStream from LibCore
				
					
				
			`Stream` will be qualified as `AK::Stream` until we remove the `Core::Stream` namespace. `IODevice` now reuses the `SeekMode` that is defined by `SeekableStream`, since defining its own would require us to qualify it with `AK::SeekMode` everywhere.
This commit is contained in:
		
							parent
							
								
									5f2ea31816
								
							
						
					
					
						commit
						8464da1439
					
				
					 96 changed files with 620 additions and 586 deletions
				
			
		|  | @ -19,6 +19,7 @@ set(AK_SOURCES | ||||||
|     NumberFormat.cpp |     NumberFormat.cpp | ||||||
|     Random.cpp |     Random.cpp | ||||||
|     StackInfo.cpp |     StackInfo.cpp | ||||||
|  |     Stream.cpp | ||||||
|     String.cpp |     String.cpp | ||||||
|     StringBuilder.cpp |     StringBuilder.cpp | ||||||
|     StringFloatingPointConversions.cpp |     StringFloatingPointConversions.cpp | ||||||
|  |  | ||||||
|  | @ -35,6 +35,8 @@ class StackInfo; | ||||||
| class DeprecatedFlyString; | class DeprecatedFlyString; | ||||||
| class DeprecatedString; | class DeprecatedString; | ||||||
| class DeprecatedStringCodePointIterator; | class DeprecatedStringCodePointIterator; | ||||||
|  | class SeekableStream; | ||||||
|  | class Stream; | ||||||
| class StringBuilder; | class StringBuilder; | ||||||
| class StringImpl; | class StringImpl; | ||||||
| class StringView; | class StringView; | ||||||
|  | @ -183,9 +185,11 @@ using AK::Optional; | ||||||
| using AK::OwnPtr; | using AK::OwnPtr; | ||||||
| using AK::ReadonlyBytes; | using AK::ReadonlyBytes; | ||||||
| using AK::RefPtr; | using AK::RefPtr; | ||||||
|  | using AK::SeekableStream; | ||||||
| using AK::SinglyLinkedList; | using AK::SinglyLinkedList; | ||||||
| using AK::Span; | using AK::Span; | ||||||
| using AK::StackInfo; | using AK::StackInfo; | ||||||
|  | using AK::Stream; | ||||||
| using AK::String; | using AK::String; | ||||||
| using AK::StringBuilder; | using AK::StringBuilder; | ||||||
| using AK::StringImpl; | using AK::StringImpl; | ||||||
|  |  | ||||||
							
								
								
									
										132
									
								
								AK/Stream.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								AK/Stream.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,132 @@ | ||||||
|  | /*
 | ||||||
|  |  * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> | ||||||
|  |  * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com> | ||||||
|  |  * | ||||||
|  |  * SPDX-License-Identifier: BSD-2-Clause | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #include <AK/ByteBuffer.h> | ||||||
|  | #include <AK/Format.h> | ||||||
|  | #include <AK/Stream.h> | ||||||
|  | 
 | ||||||
|  | namespace AK { | ||||||
|  | 
 | ||||||
|  | ErrorOr<void> Stream::read_entire_buffer(Bytes buffer) | ||||||
|  | { | ||||||
|  |     size_t nread = 0; | ||||||
|  |     while (nread < buffer.size()) { | ||||||
|  |         if (is_eof()) | ||||||
|  |             return Error::from_string_literal("Reached end-of-file before filling the entire buffer"); | ||||||
|  | 
 | ||||||
|  |         auto result = read(buffer.slice(nread)); | ||||||
|  |         if (result.is_error()) { | ||||||
|  |             if (result.error().is_errno() && result.error().code() == EINTR) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return result.release_error(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         nread += result.value().size(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return {}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<ByteBuffer> Stream::read_until_eof(size_t block_size) | ||||||
|  | { | ||||||
|  |     return read_until_eof_impl(block_size); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<ByteBuffer> Stream::read_until_eof_impl(size_t block_size, size_t expected_file_size) | ||||||
|  | { | ||||||
|  |     ByteBuffer data; | ||||||
|  |     data.ensure_capacity(expected_file_size); | ||||||
|  | 
 | ||||||
|  |     size_t total_read = 0; | ||||||
|  |     Bytes buffer; | ||||||
|  |     while (!is_eof()) { | ||||||
|  |         if (buffer.is_empty()) { | ||||||
|  |             buffer = TRY(data.get_bytes_for_writing(block_size)); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         auto nread = TRY(read(buffer)).size(); | ||||||
|  |         total_read += nread; | ||||||
|  |         buffer = buffer.slice(nread); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     data.resize(total_read); | ||||||
|  |     return data; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<void> Stream::discard(size_t discarded_bytes) | ||||||
|  | { | ||||||
|  |     // Note: This was chosen arbitrarily.
 | ||||||
|  |     // Note: This can't be PAGE_SIZE because it is defined to sysconf() on Lagom.
 | ||||||
|  |     constexpr size_t continuous_read_size = 4096; | ||||||
|  | 
 | ||||||
|  |     Array<u8, continuous_read_size> buffer; | ||||||
|  | 
 | ||||||
|  |     while (discarded_bytes > 0) { | ||||||
|  |         if (is_eof()) | ||||||
|  |             return Error::from_string_literal("Reached end-of-file before reading all discarded bytes"); | ||||||
|  | 
 | ||||||
|  |         auto slice = TRY(read(buffer.span().slice(0, min(discarded_bytes, continuous_read_size)))); | ||||||
|  |         discarded_bytes -= slice.size(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return {}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<void> Stream::write_entire_buffer(ReadonlyBytes buffer) | ||||||
|  | { | ||||||
|  |     size_t nwritten = 0; | ||||||
|  |     while (nwritten < buffer.size()) { | ||||||
|  |         auto result = write(buffer.slice(nwritten)); | ||||||
|  |         if (result.is_error()) { | ||||||
|  |             if (result.error().is_errno() && result.error().code() == EINTR) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return result.release_error(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         nwritten += result.value(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return {}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<size_t> SeekableStream::tell() const | ||||||
|  | { | ||||||
|  |     // Seek with 0 and SEEK_CUR does not modify anything despite the const_cast,
 | ||||||
|  |     // so it's safe to do this.
 | ||||||
|  |     return const_cast<SeekableStream*>(this)->seek(0, SeekMode::FromCurrentPosition); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<size_t> SeekableStream::size() | ||||||
|  | { | ||||||
|  |     auto original_position = TRY(tell()); | ||||||
|  | 
 | ||||||
|  |     auto seek_result = seek(0, SeekMode::FromEndPosition); | ||||||
|  |     if (seek_result.is_error()) { | ||||||
|  |         // Let's try to restore the original position, just in case.
 | ||||||
|  |         auto restore_result = seek(original_position, SeekMode::SetPosition); | ||||||
|  |         if (restore_result.is_error()) { | ||||||
|  |             dbgln("SeekableStream::size: Couldn't restore initial position, stream might have incorrect position now!"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return seek_result.release_error(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     TRY(seek(original_position, SeekMode::SetPosition)); | ||||||
|  |     return seek_result.value(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<void> SeekableStream::discard(size_t discarded_bytes) | ||||||
|  | { | ||||||
|  |     TRY(seek(discarded_bytes, SeekMode::FromCurrentPosition)); | ||||||
|  |     return {}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										133
									
								
								AK/Stream.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								AK/Stream.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,133 @@ | ||||||
|  | /*
 | ||||||
|  |  * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com> | ||||||
|  |  * Copyright (c) 2022, the SerenityOS developers. | ||||||
|  |  * | ||||||
|  |  * SPDX-License-Identifier: BSD-2-Clause | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <AK/Error.h> | ||||||
|  | #include <AK/Forward.h> | ||||||
|  | #include <AK/Traits.h> | ||||||
|  | 
 | ||||||
|  | namespace AK { | ||||||
|  | 
 | ||||||
|  | /// The base, abstract class for stream operations. This class defines the
 | ||||||
|  | /// operations one can perform on every stream.
 | ||||||
|  | /// Operations without a sensible default that are unsupported by an implementation
 | ||||||
|  | /// of a Stream should return EBADF as an error.
 | ||||||
|  | class Stream { | ||||||
|  | public: | ||||||
|  |     /// Reads into a buffer, with the maximum size being the size of the buffer.
 | ||||||
|  |     /// The amount of bytes read can be smaller than the size of the buffer.
 | ||||||
|  |     /// Returns either the bytes that were read, or an errno in the case of
 | ||||||
|  |     /// failure.
 | ||||||
|  |     virtual ErrorOr<Bytes> read(Bytes) = 0; | ||||||
|  |     /// Tries to fill the entire buffer through reading. Returns whether the
 | ||||||
|  |     /// buffer was filled without an error.
 | ||||||
|  |     virtual ErrorOr<void> read_entire_buffer(Bytes); | ||||||
|  |     /// Reads the stream until EOF, storing the contents into a ByteBuffer which
 | ||||||
|  |     /// is returned once EOF is encountered. The block size determines the size
 | ||||||
|  |     /// of newly allocated chunks while reading.
 | ||||||
|  |     virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096); | ||||||
|  |     /// Discards the given number of bytes from the stream. As this is usually used
 | ||||||
|  |     /// as an efficient version of `read_entire_buffer`, it returns an error
 | ||||||
|  |     /// if reading failed or if not all bytes could be discarded.
 | ||||||
|  |     /// Unless specifically overwritten, this just uses read() to read into an
 | ||||||
|  |     /// internal stack-based buffer.
 | ||||||
|  |     virtual ErrorOr<void> discard(size_t discarded_bytes); | ||||||
|  | 
 | ||||||
|  |     /// Tries to write the entire contents of the buffer. It is possible for
 | ||||||
|  |     /// less than the full buffer to be written. Returns either the amount of
 | ||||||
|  |     /// bytes written into the stream, or an errno in the case of failure.
 | ||||||
|  |     virtual ErrorOr<size_t> write(ReadonlyBytes) = 0; | ||||||
|  |     /// Same as write, but does not return until either the entire buffer
 | ||||||
|  |     /// contents are written or an error occurs.
 | ||||||
|  |     virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes); | ||||||
|  | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs<ErrorOr<T>>; }) | ||||||
|  |     ErrorOr<T> read_value() | ||||||
|  |     { | ||||||
|  |         return T::read_from_stream(*this); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     requires(Traits<T>::is_trivially_serializable()) | ||||||
|  |     ErrorOr<T> read_value() | ||||||
|  |     { | ||||||
|  |         alignas(T) u8 buffer[sizeof(T)] = {}; | ||||||
|  |         TRY(read_entire_buffer({ &buffer, sizeof(buffer) })); | ||||||
|  |         return bit_cast<T>(buffer); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     requires(requires(T t, Stream& stream) { { t.write_to_stream(stream) } -> SameAs<ErrorOr<void>>; }) | ||||||
|  |     ErrorOr<void> write_value(T const& value) | ||||||
|  |     { | ||||||
|  |         return value.write_to_stream(*this); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     requires(Traits<T>::is_trivially_serializable()) | ||||||
|  |     ErrorOr<void> write_value(T const& value) | ||||||
|  |     { | ||||||
|  |         return write_entire_buffer({ &value, sizeof(value) }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /// Returns whether the stream has reached the end of file. For sockets,
 | ||||||
|  |     /// this most likely means that the protocol has disconnected (in the case
 | ||||||
|  |     /// of TCP). For seekable streams, this means the end of the file. Note that
 | ||||||
|  |     /// is_eof will only return true _after_ a read with 0 length, so this
 | ||||||
|  |     /// method should be called after a read.
 | ||||||
|  |     virtual bool is_eof() const = 0; | ||||||
|  | 
 | ||||||
|  |     virtual bool is_open() const = 0; | ||||||
|  |     virtual void close() = 0; | ||||||
|  | 
 | ||||||
|  |     virtual ~Stream() | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | protected: | ||||||
|  |     /// Provides a default implementation of read_until_eof that works for streams
 | ||||||
|  |     /// that behave like POSIX file descriptors. expected_file_size can be
 | ||||||
|  |     /// passed as a heuristic for what the Stream subclass expects the file
 | ||||||
|  |     /// content size to be in order to reduce allocations (does not affect
 | ||||||
|  |     /// actual reading).
 | ||||||
|  |     ErrorOr<ByteBuffer> read_until_eof_impl(size_t block_size, size_t expected_file_size = 0); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | enum class SeekMode { | ||||||
|  |     SetPosition, | ||||||
|  |     FromCurrentPosition, | ||||||
|  |     FromEndPosition, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /// Adds seekability to a Stream. Classes inheriting from SeekableStream
 | ||||||
|  | /// will be seekable to any point in the stream.
 | ||||||
|  | class SeekableStream : public Stream { | ||||||
|  | public: | ||||||
|  |     /// Seeks to the given position in the given mode. Returns either the
 | ||||||
|  |     /// current position of the file, or an errno in the case of an error.
 | ||||||
|  |     virtual ErrorOr<size_t> seek(i64 offset, SeekMode) = 0; | ||||||
|  |     /// Returns the current position of the file, or an errno in the case of
 | ||||||
|  |     /// an error.
 | ||||||
|  |     virtual ErrorOr<size_t> tell() const; | ||||||
|  |     /// Returns the total size of the stream, or an errno in the case of an
 | ||||||
|  |     /// error. May not preserve the original position on the stream on failure.
 | ||||||
|  |     virtual ErrorOr<size_t> size(); | ||||||
|  |     /// Shrinks or extends the stream to the given size. Returns an errno in
 | ||||||
|  |     /// the case of an error.
 | ||||||
|  |     virtual ErrorOr<void> truncate(off_t length) = 0; | ||||||
|  |     /// Seeks until after the given amount of bytes to be discarded instead of
 | ||||||
|  |     /// reading and discarding everything manually;
 | ||||||
|  |     virtual ErrorOr<void> discard(size_t discarded_bytes) override; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #if USING_AK_GLOBALLY | ||||||
|  | using AK::SeekMode; | ||||||
|  | #endif | ||||||
|  | @ -666,7 +666,7 @@ T* ret = reinterpret_cast<T*>(buffer); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ```cpp | ```cpp | ||||||
| // Core::Stream::SeekableStream::tell() | // SeekableStream::tell() | ||||||
| 
 | 
 | ||||||
| // Seek with 0 and SEEK_CUR does not modify anything despite the const_cast, | // Seek with 0 and SEEK_CUR does not modify anything despite the const_cast, | ||||||
| // so it's safe to do this. | // so it's safe to do this. | ||||||
|  |  | ||||||
|  | @ -44,7 +44,7 @@ private: | ||||||
| 
 | 
 | ||||||
|         virtual void set_should_buffer_all_input(bool) override { } |         virtual void set_should_buffer_all_input(bool) override { } | ||||||
|         virtual bool stop() override { return false; } |         virtual bool stop() override { return false; } | ||||||
|         virtual void stream_into(Core::Stream::Stream&) override { } |         virtual void stream_into(AK::Stream&) override { } | ||||||
| 
 | 
 | ||||||
|         void did_finish(); |         void did_finish(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -338,7 +338,7 @@ public:)~~~"); | ||||||
|     static i32 static_message_id() { return (int)MessageID::@message.pascal_name@; } |     static i32 static_message_id() { return (int)MessageID::@message.pascal_name@; } | ||||||
|     virtual const char* message_name() const override { return "@endpoint.name@::@message.pascal_name@"; } |     virtual const char* message_name() const override { return "@endpoint.name@::@message.pascal_name@"; } | ||||||
| 
 | 
 | ||||||
|     static ErrorOr<NonnullOwnPtr<@message.pascal_name@>> decode(Core::Stream::Stream& stream, Core::Stream::LocalSocket& socket) |     static ErrorOr<NonnullOwnPtr<@message.pascal_name@>> decode(AK::Stream& stream, Core::Stream::LocalSocket& socket) | ||||||
|     { |     { | ||||||
|         IPC::Decoder decoder { stream, socket };)~~~"); |         IPC::Decoder decoder { stream, socket };)~~~"); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -450,7 +450,7 @@ static ErrorOr<void> parse_name_aliases(Core::Stream::BufferedFile& file, Unicod | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> parse_value_alias_list(Core::Stream::BufferedFile& file, StringView desired_category, Vector<DeprecatedString> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false) | static ErrorOr<void> parse_value_alias_list(Core::Stream::BufferedFile& file, StringView desired_category, Vector<DeprecatedString> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false) | ||||||
| { | { | ||||||
|     TRY(file.seek(0, Core::Stream::SeekMode::SetPosition)); |     TRY(file.seek(0, SeekMode::SetPosition)); | ||||||
|     Array<u8, 1024> buffer; |     Array<u8, 1024> buffer; | ||||||
| 
 | 
 | ||||||
|     auto append_alias = [&](auto alias, auto value) { |     auto append_alias = [&](auto alias, auto value) { | ||||||
|  | @ -646,7 +646,7 @@ static ErrorOr<void> parse_block_display_names(Core::Stream::BufferedFile& file, | ||||||
|         unicode_data.block_display_names.append({ code_point_range, index }); |         unicode_data.block_display_names.append({ code_point_range, index }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     TRY(file.seek(0, Core::Stream::SeekMode::SetPosition)); |     TRY(file.seek(0, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ void displayln(CheckedFormatString<Args...> format_string, Args const&... args) | ||||||
| 
 | 
 | ||||||
| void displayln() { user_display("\n", 1); } | void displayln() { user_display("\n", 1); } | ||||||
| 
 | 
 | ||||||
| class UserDisplayStream final : public Core::Stream::Stream { | class UserDisplayStream final : public AK::Stream { | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override { return Error::from_string_view("Not readable"sv); }; |     virtual ErrorOr<Bytes> read(Bytes) override { return Error::from_string_view("Not readable"sv); }; | ||||||
|     virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override |     virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -53,19 +53,19 @@ TEST_CASE(file_get_read_position) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         off_t offset = 0; |         off_t offset = 0; | ||||||
|         VERIFY(file->seek(0, Core::SeekMode::FromCurrentPosition, &offset)); |         VERIFY(file->seek(0, SeekMode::FromCurrentPosition, &offset)); | ||||||
|         EXPECT_EQ(offset, static_cast<off_t>(i + step_size)); |         EXPECT_EQ(offset, static_cast<off_t>(i + step_size)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     { |     { | ||||||
|         off_t offset = 0; |         off_t offset = 0; | ||||||
|         VERIFY(file->seek(0, Core::SeekMode::FromEndPosition, &offset)); |         VERIFY(file->seek(0, SeekMode::FromEndPosition, &offset)); | ||||||
|         EXPECT_EQ(offset, 10240); |         EXPECT_EQ(offset, 10240); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     { |     { | ||||||
|         off_t offset = 0; |         off_t offset = 0; | ||||||
|         VERIFY(file->seek(0, Core::SeekMode::SetPosition, &offset)); |         VERIFY(file->seek(0, SeekMode::SetPosition, &offset)); | ||||||
|         EXPECT_EQ(offset, 0); |         EXPECT_EQ(offset, 0); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -89,17 +89,17 @@ TEST_CASE(file_seeking_around) | ||||||
| 
 | 
 | ||||||
|     StringView buffer_contents { buffer.bytes() }; |     StringView buffer_contents { buffer.bytes() }; | ||||||
| 
 | 
 | ||||||
|     EXPECT(!file->seek(500, Core::Stream::SeekMode::SetPosition).is_error()); |     EXPECT(!file->seek(500, SeekMode::SetPosition).is_error()); | ||||||
|     EXPECT_EQ(file->tell().release_value(), 500ul); |     EXPECT_EQ(file->tell().release_value(), 500ul); | ||||||
|     EXPECT(!file->read_entire_buffer(buffer).is_error()); |     EXPECT(!file->read_entire_buffer(buffer).is_error()); | ||||||
|     EXPECT_EQ(buffer_contents, expected_seek_contents1); |     EXPECT_EQ(buffer_contents, expected_seek_contents1); | ||||||
| 
 | 
 | ||||||
|     EXPECT(!file->seek(234, Core::Stream::SeekMode::FromCurrentPosition).is_error()); |     EXPECT(!file->seek(234, SeekMode::FromCurrentPosition).is_error()); | ||||||
|     EXPECT_EQ(file->tell().release_value(), 750ul); |     EXPECT_EQ(file->tell().release_value(), 750ul); | ||||||
|     EXPECT(!file->read_entire_buffer(buffer).is_error()); |     EXPECT(!file->read_entire_buffer(buffer).is_error()); | ||||||
|     EXPECT_EQ(buffer_contents, expected_seek_contents2); |     EXPECT_EQ(buffer_contents, expected_seek_contents2); | ||||||
| 
 | 
 | ||||||
|     EXPECT(!file->seek(-105, Core::Stream::SeekMode::FromEndPosition).is_error()); |     EXPECT(!file->seek(-105, SeekMode::FromEndPosition).is_error()); | ||||||
|     EXPECT_EQ(file->tell().release_value(), 8597ul); |     EXPECT_EQ(file->tell().release_value(), 8597ul); | ||||||
|     EXPECT(!file->read_entire_buffer(buffer).is_error()); |     EXPECT(!file->read_entire_buffer(buffer).is_error()); | ||||||
|     EXPECT_EQ(buffer_contents, expected_seek_contents3); |     EXPECT_EQ(buffer_contents, expected_seek_contents3); | ||||||
|  | @ -122,7 +122,7 @@ TEST_CASE(file_adopt_fd) | ||||||
| 
 | 
 | ||||||
|     StringView buffer_contents { buffer.bytes() }; |     StringView buffer_contents { buffer.bytes() }; | ||||||
| 
 | 
 | ||||||
|     EXPECT(!file->seek(500, Core::Stream::SeekMode::SetPosition).is_error()); |     EXPECT(!file->seek(500, SeekMode::SetPosition).is_error()); | ||||||
|     EXPECT_EQ(file->tell().release_value(), 500ul); |     EXPECT_EQ(file->tell().release_value(), 500ul); | ||||||
|     EXPECT(!file->read_entire_buffer(buffer).is_error()); |     EXPECT(!file->read_entire_buffer(buffer).is_error()); | ||||||
|     EXPECT_EQ(buffer_contents, expected_seek_contents1); |     EXPECT_EQ(buffer_contents, expected_seek_contents1); | ||||||
|  | @ -428,14 +428,14 @@ TEST_CASE(buffered_long_file_read) | ||||||
|     auto file = maybe_buffered_file.release_value(); |     auto file = maybe_buffered_file.release_value(); | ||||||
| 
 | 
 | ||||||
|     auto buffer = ByteBuffer::create_uninitialized(4096).release_value(); |     auto buffer = ByteBuffer::create_uninitialized(4096).release_value(); | ||||||
|     EXPECT(!file->seek(255, Core::Stream::SeekMode::SetPosition).is_error()); |     EXPECT(!file->seek(255, SeekMode::SetPosition).is_error()); | ||||||
|     EXPECT(file->can_read_line().release_value()); |     EXPECT(file->can_read_line().release_value()); | ||||||
|     auto maybe_line = file->read_line(buffer); |     auto maybe_line = file->read_line(buffer); | ||||||
|     EXPECT(!maybe_line.is_error()); |     EXPECT(!maybe_line.is_error()); | ||||||
|     EXPECT_EQ(maybe_line.value().length(), 4095ul); // 4095 bytes on the third line
 |     EXPECT_EQ(maybe_line.value().length(), 4095ul); // 4095 bytes on the third line
 | ||||||
| 
 | 
 | ||||||
|     // Testing that buffering with seeking works properly
 |     // Testing that buffering with seeking works properly
 | ||||||
|     EXPECT(!file->seek(365, Core::Stream::SeekMode::SetPosition).is_error()); |     EXPECT(!file->seek(365, SeekMode::SetPosition).is_error()); | ||||||
|     auto maybe_after_seek_line = file->read_line(buffer); |     auto maybe_after_seek_line = file->read_line(buffer); | ||||||
|     EXPECT(!maybe_after_seek_line.is_error()); |     EXPECT(!maybe_after_seek_line.is_error()); | ||||||
|     EXPECT_EQ(maybe_after_seek_line.value().length(), 3985ul); // 4095 - 110
 |     EXPECT_EQ(maybe_after_seek_line.value().length(), 3985ul); // 4095 - 110
 | ||||||
|  | @ -499,7 +499,7 @@ TEST_CASE(buffered_file_tell_and_seek) | ||||||
| 
 | 
 | ||||||
|     // Seek seven characters forward.
 |     // Seek seven characters forward.
 | ||||||
|     { |     { | ||||||
|         auto current_offset = buffered_file->seek(7, Core::Stream::SeekMode::FromCurrentPosition).release_value(); |         auto current_offset = buffered_file->seek(7, SeekMode::FromCurrentPosition).release_value(); | ||||||
|         EXPECT_EQ(current_offset, 9ul); |         EXPECT_EQ(current_offset, 9ul); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -513,7 +513,7 @@ TEST_CASE(buffered_file_tell_and_seek) | ||||||
| 
 | 
 | ||||||
|     // Seek five characters backwards.
 |     // Seek five characters backwards.
 | ||||||
|     { |     { | ||||||
|         auto current_offset = buffered_file->seek(-5, Core::Stream::SeekMode::FromCurrentPosition).release_value(); |         auto current_offset = buffered_file->seek(-5, SeekMode::FromCurrentPosition).release_value(); | ||||||
|         EXPECT_EQ(current_offset, 5ul); |         EXPECT_EQ(current_offset, 5ul); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -527,7 +527,7 @@ TEST_CASE(buffered_file_tell_and_seek) | ||||||
| 
 | 
 | ||||||
|     // Seek back to the beginning.
 |     // Seek back to the beginning.
 | ||||||
|     { |     { | ||||||
|         auto current_offset = buffered_file->seek(0, Core::Stream::SeekMode::SetPosition).release_value(); |         auto current_offset = buffered_file->seek(0, SeekMode::SetPosition).release_value(); | ||||||
|         EXPECT_EQ(current_offset, 0ul); |         EXPECT_EQ(current_offset, 0ul); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -541,7 +541,7 @@ TEST_CASE(buffered_file_tell_and_seek) | ||||||
| 
 | 
 | ||||||
|     // Seek beyond the buffer size, which should invalidate the buffer.
 |     // Seek beyond the buffer size, which should invalidate the buffer.
 | ||||||
|     { |     { | ||||||
|         auto current_offset = buffered_file->seek(12, Core::Stream::SeekMode::SetPosition).release_value(); |         auto current_offset = buffered_file->seek(12, SeekMode::SetPosition).release_value(); | ||||||
|         EXPECT_EQ(current_offset, 12ul); |         EXPECT_EQ(current_offset, 12ul); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -697,7 +697,7 @@ TEST_CASE(allocating_memory_stream_10kb) | ||||||
| 
 | 
 | ||||||
|     EXPECT_EQ(stream.used_buffer_size(), file_size); |     EXPECT_EQ(stream.used_buffer_size(), file_size); | ||||||
| 
 | 
 | ||||||
|     MUST(file->seek(0, Core::Stream::SeekMode::SetPosition)); |     MUST(file->seek(0, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     // Check the stream contents when reading back.
 |     // Check the stream contents when reading back.
 | ||||||
|     size_t offset = 0; |     size_t offset = 0; | ||||||
|  | @ -727,8 +727,8 @@ TEST_CASE(little_endian_bit_stream_input_output_match) | ||||||
| 
 | 
 | ||||||
|     // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks,
 |     // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks,
 | ||||||
|     // so testing with sizes that will not trigger a write will yield unexpected results.
 |     // so testing with sizes that will not trigger a write will yield unexpected results.
 | ||||||
|     auto bit_write_stream = MUST(Core::Stream::LittleEndianOutputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream))); |     auto bit_write_stream = MUST(Core::Stream::LittleEndianOutputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream))); | ||||||
|     auto bit_read_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream))); |     auto bit_read_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream))); | ||||||
| 
 | 
 | ||||||
|     // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits.
 |     // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits.
 | ||||||
|     { |     { | ||||||
|  | @ -783,8 +783,8 @@ TEST_CASE(big_endian_bit_stream_input_output_match) | ||||||
| 
 | 
 | ||||||
|     // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks,
 |     // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks,
 | ||||||
|     // so testing with sizes that will not trigger a write will yield unexpected results.
 |     // so testing with sizes that will not trigger a write will yield unexpected results.
 | ||||||
|     auto bit_write_stream = MUST(Core::Stream::BigEndianOutputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream))); |     auto bit_write_stream = MUST(Core::Stream::BigEndianOutputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream))); | ||||||
|     auto bit_read_stream = MUST(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream))); |     auto bit_read_stream = MUST(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream))); | ||||||
| 
 | 
 | ||||||
|     // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits.
 |     // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits.
 | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -148,7 +148,7 @@ private: | ||||||
|     { |     { | ||||||
|         if (file) { |         if (file) { | ||||||
|             // Seeking to the beginning causes a data refresh!
 |             // Seeking to the beginning causes a data refresh!
 | ||||||
|             TRY(file->seek(0, Core::Stream::SeekMode::SetPosition)); |             TRY(file->seek(0, SeekMode::SetPosition)); | ||||||
|         } else { |         } else { | ||||||
|             file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read)); |             file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -64,7 +64,7 @@ bool HexDocumentMemory::write_to_file(NonnullRefPtr<Core::File> file) | ||||||
|     if (!file->write(m_buffer.data(), m_buffer.size())) |     if (!file->write(m_buffer.data(), m_buffer.size())) | ||||||
|         return false; |         return false; | ||||||
|     for (auto& change : m_changes) { |     for (auto& change : m_changes) { | ||||||
|         file->seek(change.key, Core::SeekMode::SetPosition); |         file->seek(change.key, SeekMode::SetPosition); | ||||||
|         file->write(&change.value, 1); |         file->write(&change.value, 1); | ||||||
|     } |     } | ||||||
|     return true; |     return true; | ||||||
|  | @ -79,7 +79,7 @@ HexDocumentFile::HexDocumentFile(NonnullRefPtr<Core::File> file) | ||||||
| void HexDocumentFile::write_to_file() | void HexDocumentFile::write_to_file() | ||||||
| { | { | ||||||
|     for (auto& change : m_changes) { |     for (auto& change : m_changes) { | ||||||
|         m_file->seek(change.key, Core::SeekMode::SetPosition); |         m_file->seek(change.key, SeekMode::SetPosition); | ||||||
|         m_file->write(&change.value, 1); |         m_file->write(&change.value, 1); | ||||||
|     } |     } | ||||||
|     clear_changes(); |     clear_changes(); | ||||||
|  | @ -105,7 +105,7 @@ bool HexDocumentFile::write_to_file(NonnullRefPtr<Core::File> file) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (auto& change : m_changes) { |     for (auto& change : m_changes) { | ||||||
|         file->seek(change.key, Core::SeekMode::SetPosition); |         file->seek(change.key, SeekMode::SetPosition); | ||||||
|         file->write(&change.value, 1); |         file->write(&change.value, 1); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -149,12 +149,12 @@ void HexDocumentFile::set_file(NonnullRefPtr<Core::File> file) | ||||||
|     m_file = file; |     m_file = file; | ||||||
| 
 | 
 | ||||||
|     off_t size = 0; |     off_t size = 0; | ||||||
|     if (!file->seek(0, Core::SeekMode::FromEndPosition, &size)) { |     if (!file->seek(0, SeekMode::FromEndPosition, &size)) { | ||||||
|         m_file_size = 0; |         m_file_size = 0; | ||||||
|     } else { |     } else { | ||||||
|         m_file_size = size; |         m_file_size = size; | ||||||
|     } |     } | ||||||
|     file->seek(0, Core::SeekMode::SetPosition); |     file->seek(0, SeekMode::SetPosition); | ||||||
| 
 | 
 | ||||||
|     clear_changes(); |     clear_changes(); | ||||||
|     // make sure the next get operation triggers a read
 |     // make sure the next get operation triggers a read
 | ||||||
|  | @ -169,7 +169,7 @@ NonnullRefPtr<Core::File> HexDocumentFile::file() const | ||||||
| void HexDocumentFile::ensure_position_in_buffer(size_t position) | void HexDocumentFile::ensure_position_in_buffer(size_t position) | ||||||
| { | { | ||||||
|     if (position < m_buffer_file_pos || position >= m_buffer_file_pos + m_buffer.size()) { |     if (position < m_buffer_file_pos || position >= m_buffer_file_pos + m_buffer.size()) { | ||||||
|         m_file->seek(position, Core::SeekMode::SetPosition); |         m_file->seek(position, SeekMode::SetPosition); | ||||||
|         m_file->read(m_buffer.data(), m_buffer.size()); |         m_file->read(m_buffer.data(), m_buffer.size()); | ||||||
|         m_buffer_file_pos = position; |         m_buffer_file_pos = position; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -172,7 +172,7 @@ RefPtr<Gfx::Bitmap> Image::copy_bitmap(Selection const& selection) const | ||||||
|     return cropped_bitmap_or_error.release_value_but_fixme_should_propagate_errors(); |     return cropped_bitmap_or_error.release_value_but_fixme_should_propagate_errors(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> Image::export_bmp_to_file(NonnullOwnPtr<Core::Stream::Stream> stream, bool preserve_alpha_channel) const | ErrorOr<void> Image::export_bmp_to_file(NonnullOwnPtr<AK::Stream> stream, bool preserve_alpha_channel) const | ||||||
| { | { | ||||||
|     auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; |     auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; | ||||||
|     auto bitmap = TRY(compose_bitmap(bitmap_format)); |     auto bitmap = TRY(compose_bitmap(bitmap_format)); | ||||||
|  | @ -183,7 +183,7 @@ ErrorOr<void> Image::export_bmp_to_file(NonnullOwnPtr<Core::Stream::Stream> stre | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> Image::export_png_to_file(NonnullOwnPtr<Core::Stream::Stream> stream, bool preserve_alpha_channel) const | ErrorOr<void> Image::export_png_to_file(NonnullOwnPtr<AK::Stream> stream, bool preserve_alpha_channel) const | ||||||
| { | { | ||||||
|     auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; |     auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; | ||||||
|     auto bitmap = TRY(compose_bitmap(bitmap_format)); |     auto bitmap = TRY(compose_bitmap(bitmap_format)); | ||||||
|  | @ -193,7 +193,7 @@ ErrorOr<void> Image::export_png_to_file(NonnullOwnPtr<Core::Stream::Stream> stre | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> Image::export_qoi_to_file(NonnullOwnPtr<Core::Stream::Stream> stream) const | ErrorOr<void> Image::export_qoi_to_file(NonnullOwnPtr<AK::Stream> stream) const | ||||||
| { | { | ||||||
|     auto bitmap = TRY(compose_bitmap(Gfx::BitmapFormat::BGRA8888)); |     auto bitmap = TRY(compose_bitmap(Gfx::BitmapFormat::BGRA8888)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -72,9 +72,9 @@ public: | ||||||
|     void paint_into(GUI::Painter&, Gfx::IntRect const& dest_rect) const; |     void paint_into(GUI::Painter&, Gfx::IntRect const& dest_rect) const; | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> serialize_as_json(JsonObjectSerializer<StringBuilder>& json) const; |     ErrorOr<void> serialize_as_json(JsonObjectSerializer<StringBuilder>& json) const; | ||||||
|     ErrorOr<void> export_bmp_to_file(NonnullOwnPtr<Core::Stream::Stream>, bool preserve_alpha_channel) const; |     ErrorOr<void> export_bmp_to_file(NonnullOwnPtr<AK::Stream>, bool preserve_alpha_channel) const; | ||||||
|     ErrorOr<void> export_png_to_file(NonnullOwnPtr<Core::Stream::Stream>, bool preserve_alpha_channel) const; |     ErrorOr<void> export_png_to_file(NonnullOwnPtr<AK::Stream>, bool preserve_alpha_channel) const; | ||||||
|     ErrorOr<void> export_qoi_to_file(NonnullOwnPtr<Core::Stream::Stream>) const; |     ErrorOr<void> export_qoi_to_file(NonnullOwnPtr<AK::Stream>) const; | ||||||
| 
 | 
 | ||||||
|     void move_layer_to_front(Layer&); |     void move_layer_to_front(Layer&); | ||||||
|     void move_layer_to_back(Layer&); |     void move_layer_to_back(Layer&); | ||||||
|  |  | ||||||
|  | @ -88,7 +88,7 @@ CSVExportDialogPage::CSVExportDialogPage(Sheet const& sheet) | ||||||
|     update_preview(); |     update_preview(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| auto CSVExportDialogPage::generate(Core::Stream::Stream& stream, GenerationType type) -> ErrorOr<void> | auto CSVExportDialogPage::generate(AK::Stream& stream, GenerationType type) -> ErrorOr<void> | ||||||
| { | { | ||||||
|     auto delimiter = TRY([this]() -> ErrorOr<DeprecatedString> { |     auto delimiter = TRY([this]() -> ErrorOr<DeprecatedString> { | ||||||
|         if (m_delimiter_other_radio->is_checked()) { |         if (m_delimiter_other_radio->is_checked()) { | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ struct CSVExportDialogPage { | ||||||
|         Preview |         Preview | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> generate(Core::Stream::Stream&, GenerationType); |     ErrorOr<void> generate(AK::Stream&, GenerationType); | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
|     void update_preview(); |     void update_preview(); | ||||||
|  |  | ||||||
|  | @ -15,13 +15,13 @@ namespace Writer { | ||||||
| class CSV { | class CSV { | ||||||
| public: | public: | ||||||
|     template<typename ContainerType> |     template<typename ContainerType> | ||||||
|     static ErrorOr<void> generate(Core::Stream::Stream& output, ContainerType const& data, Vector<StringView> headers = {}, WriterBehavior behaviors = default_behaviors()) |     static ErrorOr<void> generate(AK::Stream& output, ContainerType const& data, Vector<StringView> headers = {}, WriterBehavior behaviors = default_behaviors()) | ||||||
|     { |     { | ||||||
|         return XSV<ContainerType>::generate(output, data, { ",", "\"", WriterTraits::Repeat }, move(headers), behaviors); |         return XSV<ContainerType>::generate(output, data, { ",", "\"", WriterTraits::Repeat }, move(headers), behaviors); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     template<typename ContainerType> |     template<typename ContainerType> | ||||||
|     static ErrorOr<void> generate_preview(Core::Stream::Stream& output, ContainerType const& data, Vector<StringView> headers = {}, WriterBehavior behaviors = default_behaviors()) |     static ErrorOr<void> generate_preview(AK::Stream& output, ContainerType const& data, Vector<StringView> headers = {}, WriterBehavior behaviors = default_behaviors()) | ||||||
|     { |     { | ||||||
|         return XSV<ContainerType>::generate_preview(output, data, { ",", "\"", WriterTraits::Repeat }, move(headers), behaviors); |         return XSV<ContainerType>::generate_preview(output, data, { ",", "\"", WriterTraits::Repeat }, move(headers), behaviors); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -42,7 +42,7 @@ constexpr WriterBehavior default_behaviors() | ||||||
| template<typename ContainerType, typename HeaderType = Vector<StringView>> | template<typename ContainerType, typename HeaderType = Vector<StringView>> | ||||||
| class XSV { | class XSV { | ||||||
| public: | public: | ||||||
|     static ErrorOr<void> generate(Core::Stream::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) |     static ErrorOr<void> generate(AK::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) | ||||||
|     { |     { | ||||||
|         auto writer = XSV(output, data, traits, headers, behaviors); |         auto writer = XSV(output, data, traits, headers, behaviors); | ||||||
|         auto with_headers = has_flag(writer.m_behaviors, WriterBehavior::WriteHeaders); |         auto with_headers = has_flag(writer.m_behaviors, WriterBehavior::WriteHeaders); | ||||||
|  | @ -63,7 +63,7 @@ public: | ||||||
|         return {}; |         return {}; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static ErrorOr<void> generate_preview(Core::Stream::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) |     static ErrorOr<void> generate_preview(AK::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) | ||||||
|     { |     { | ||||||
|         auto writer = XSV(output, data, traits, headers, behaviors); |         auto writer = XSV(output, data, traits, headers, behaviors); | ||||||
|         auto lines_written = 0; |         auto lines_written = 0; | ||||||
|  | @ -93,7 +93,7 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     XSV(Core::Stream::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) |     XSV(AK::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) | ||||||
|         : m_data(data) |         : m_data(data) | ||||||
|         , m_traits(move(traits)) |         , m_traits(move(traits)) | ||||||
|         , m_behaviors(behaviors) |         , m_behaviors(behaviors) | ||||||
|  | @ -170,7 +170,7 @@ private: | ||||||
|     WriterTraits m_traits; |     WriterTraits m_traits; | ||||||
|     WriterBehavior m_behaviors; |     WriterBehavior m_behaviors; | ||||||
|     HeaderType m_names; |     HeaderType m_names; | ||||||
|     Core::Stream::Stream& m_output; |     AK::Stream& m_output; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -500,7 +500,7 @@ void Emulator::dump_backtrace() | ||||||
|     dump_backtrace(raw_backtrace()); |     dump_backtrace(raw_backtrace()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Emulator::emit_profile_sample(Core::Stream::Stream& output) | void Emulator::emit_profile_sample(AK::Stream& output) | ||||||
| { | { | ||||||
|     if (!is_in_region_of_interest()) |     if (!is_in_region_of_interest()) | ||||||
|         return; |         return; | ||||||
|  | @ -513,7 +513,7 @@ void Emulator::emit_profile_sample(Core::Stream::Stream& output) | ||||||
|     output.write_entire_buffer(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors(); |     output.write_entire_buffer(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Emulator::emit_profile_event(Core::Stream::Stream& output, StringView event_name, DeprecatedString const& contents) | void Emulator::emit_profile_event(AK::Stream& output, StringView event_name, DeprecatedString const& contents) | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|     timeval tv {}; |     timeval tv {}; | ||||||
|  |  | ||||||
|  | @ -32,7 +32,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     Emulator(DeprecatedString const& executable_path, Vector<StringView> const& arguments, Vector<DeprecatedString> const& environment); |     Emulator(DeprecatedString const& executable_path, Vector<StringView> const& arguments, Vector<DeprecatedString> const& environment); | ||||||
| 
 | 
 | ||||||
|     void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Core::Stream::Stream* profile_stream, NonnullOwnPtrVector<DeprecatedString>* profiler_strings, Vector<int>* profiler_string_id_map) |     void set_profiling_details(bool should_dump_profile, size_t instruction_interval, AK::Stream* profile_stream, NonnullOwnPtrVector<DeprecatedString>* profiler_strings, Vector<int>* profiler_string_id_map) | ||||||
|     { |     { | ||||||
|         m_is_profiling = should_dump_profile; |         m_is_profiling = should_dump_profile; | ||||||
|         m_profile_instruction_interval = instruction_interval; |         m_profile_instruction_interval = instruction_interval; | ||||||
|  | @ -46,7 +46,7 @@ public: | ||||||
|         m_is_in_region_of_interest = value; |         m_is_in_region_of_interest = value; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Core::Stream::Stream& profile_stream() { return *m_profile_stream; } |     AK::Stream& profile_stream() { return *m_profile_stream; } | ||||||
|     NonnullOwnPtrVector<DeprecatedString>& profiler_strings() { return *m_profiler_strings; } |     NonnullOwnPtrVector<DeprecatedString>& profiler_strings() { return *m_profiler_strings; } | ||||||
|     Vector<int>& profiler_string_id_map() { return *m_profiler_string_id_map; } |     Vector<int>& profiler_string_id_map() { return *m_profiler_string_id_map; } | ||||||
| 
 | 
 | ||||||
|  | @ -139,8 +139,8 @@ private: | ||||||
| 
 | 
 | ||||||
|     void send_signal(int); |     void send_signal(int); | ||||||
| 
 | 
 | ||||||
|     void emit_profile_sample(Core::Stream::Stream&); |     void emit_profile_sample(AK::Stream&); | ||||||
|     void emit_profile_event(Core::Stream::Stream&, StringView event_name, DeprecatedString const& contents); |     void emit_profile_event(AK::Stream&, StringView event_name, DeprecatedString const& contents); | ||||||
| 
 | 
 | ||||||
|     int virt$accept4(FlatPtr); |     int virt$accept4(FlatPtr); | ||||||
|     u32 virt$allocate_tls(FlatPtr, size_t); |     u32 virt$allocate_tls(FlatPtr, size_t); | ||||||
|  | @ -295,7 +295,7 @@ private: | ||||||
| 
 | 
 | ||||||
|     RangeAllocator m_range_allocator; |     RangeAllocator m_range_allocator; | ||||||
| 
 | 
 | ||||||
|     Core::Stream::Stream* m_profile_stream { nullptr }; |     AK::Stream* m_profile_stream { nullptr }; | ||||||
|     Vector<int>* m_profiler_string_id_map { nullptr }; |     Vector<int>* m_profiler_string_id_map { nullptr }; | ||||||
|     NonnullOwnPtrVector<DeprecatedString>* m_profiler_strings { nullptr }; |     NonnullOwnPtrVector<DeprecatedString>* m_profiler_strings { nullptr }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -57,7 +57,7 @@ int main(int argc, char** argv, char** env) | ||||||
|     if (dump_profile && profile_dump_path.is_empty()) |     if (dump_profile && profile_dump_path.is_empty()) | ||||||
|         profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid()); |         profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid()); | ||||||
| 
 | 
 | ||||||
|     OwnPtr<Core::Stream::Stream> profile_stream; |     OwnPtr<AK::Stream> profile_stream; | ||||||
|     OwnPtr<NonnullOwnPtrVector<DeprecatedString>> profile_strings; |     OwnPtr<NonnullOwnPtrVector<DeprecatedString>> profile_strings; | ||||||
|     OwnPtr<Vector<int>> profile_string_id_map; |     OwnPtr<Vector<int>> profile_string_id_map; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -51,7 +51,7 @@ ErrorOr<size_t> TarFileStream::write(ReadonlyBytes) | ||||||
|     return Error::from_errno(EBADF); |     return Error::from_errno(EBADF); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<NonnullOwnPtr<TarInputStream>> TarInputStream::construct(NonnullOwnPtr<Core::Stream::Stream> stream) | ErrorOr<NonnullOwnPtr<TarInputStream>> TarInputStream::construct(NonnullOwnPtr<AK::Stream> stream) | ||||||
| { | { | ||||||
|     auto tar_stream = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TarInputStream(move(stream)))); |     auto tar_stream = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TarInputStream(move(stream)))); | ||||||
| 
 | 
 | ||||||
|  | @ -60,7 +60,7 @@ ErrorOr<NonnullOwnPtr<TarInputStream>> TarInputStream::construct(NonnullOwnPtr<C | ||||||
|     return tar_stream; |     return tar_stream; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| TarInputStream::TarInputStream(NonnullOwnPtr<Core::Stream::Stream> stream) | TarInputStream::TarInputStream(NonnullOwnPtr<AK::Stream> stream) | ||||||
|     : m_stream(move(stream)) |     : m_stream(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  | @ -136,7 +136,7 @@ TarFileStream TarInputStream::file_contents() | ||||||
|     return TarFileStream(*this); |     return TarFileStream(*this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| TarOutputStream::TarOutputStream(MaybeOwned<Core::Stream::Stream> stream) | TarOutputStream::TarOutputStream(MaybeOwned<AK::Stream> stream) | ||||||
|     : m_stream(move(stream)) |     : m_stream(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ namespace Archive { | ||||||
| 
 | 
 | ||||||
| class TarInputStream; | class TarInputStream; | ||||||
| 
 | 
 | ||||||
| class TarFileStream : public Core::Stream::Stream { | class TarFileStream : public AK::Stream { | ||||||
| public: | public: | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|     virtual ErrorOr<size_t> write(ReadonlyBytes) override; |     virtual ErrorOr<size_t> write(ReadonlyBytes) override; | ||||||
|  | @ -34,7 +34,7 @@ private: | ||||||
| 
 | 
 | ||||||
| class TarInputStream { | class TarInputStream { | ||||||
| public: | public: | ||||||
|     static ErrorOr<NonnullOwnPtr<TarInputStream>> construct(NonnullOwnPtr<Core::Stream::Stream>); |     static ErrorOr<NonnullOwnPtr<TarInputStream>> construct(NonnullOwnPtr<AK::Stream>); | ||||||
|     ErrorOr<void> advance(); |     ErrorOr<void> advance(); | ||||||
|     bool finished() const { return m_found_end_of_archive || m_stream->is_eof(); } |     bool finished() const { return m_found_end_of_archive || m_stream->is_eof(); } | ||||||
|     ErrorOr<bool> valid() const; |     ErrorOr<bool> valid() const; | ||||||
|  | @ -45,11 +45,11 @@ public: | ||||||
|     ErrorOr<void> for_each_extended_header(F func); |     ErrorOr<void> for_each_extended_header(F func); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     TarInputStream(NonnullOwnPtr<Core::Stream::Stream>); |     TarInputStream(NonnullOwnPtr<AK::Stream>); | ||||||
|     ErrorOr<void> load_next_header(); |     ErrorOr<void> load_next_header(); | ||||||
| 
 | 
 | ||||||
|     TarFileHeader m_header; |     TarFileHeader m_header; | ||||||
|     NonnullOwnPtr<Core::Stream::Stream> m_stream; |     NonnullOwnPtr<AK::Stream> m_stream; | ||||||
|     unsigned long m_file_offset { 0 }; |     unsigned long m_file_offset { 0 }; | ||||||
|     int m_generation { 0 }; |     int m_generation { 0 }; | ||||||
|     bool m_found_end_of_archive { false }; |     bool m_found_end_of_archive { false }; | ||||||
|  | @ -59,14 +59,14 @@ private: | ||||||
| 
 | 
 | ||||||
| class TarOutputStream { | class TarOutputStream { | ||||||
| public: | public: | ||||||
|     TarOutputStream(MaybeOwned<Core::Stream::Stream>); |     TarOutputStream(MaybeOwned<AK::Stream>); | ||||||
|     ErrorOr<void> add_file(StringView path, mode_t, ReadonlyBytes); |     ErrorOr<void> add_file(StringView path, mode_t, ReadonlyBytes); | ||||||
|     ErrorOr<void> add_link(StringView path, mode_t, StringView); |     ErrorOr<void> add_link(StringView path, mode_t, StringView); | ||||||
|     ErrorOr<void> add_directory(StringView path, mode_t); |     ErrorOr<void> add_directory(StringView path, mode_t); | ||||||
|     ErrorOr<void> finish(); |     ErrorOr<void> finish(); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     MaybeOwned<Core::Stream::Stream> m_stream; |     MaybeOwned<AK::Stream> m_stream; | ||||||
|     bool m_finished { false }; |     bool m_finished { false }; | ||||||
| 
 | 
 | ||||||
|     friend class TarFileStream; |     friend class TarFileStream; | ||||||
|  |  | ||||||
|  | @ -100,7 +100,7 @@ ErrorOr<bool> Zip::for_each_member(Function<IterationDecision(ZipMember const&)> | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ZipOutputStream::ZipOutputStream(NonnullOwnPtr<Core::Stream::Stream> stream) | ZipOutputStream::ZipOutputStream(NonnullOwnPtr<AK::Stream> stream) | ||||||
|     : m_stream(move(stream)) |     : m_stream(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -55,7 +55,7 @@ struct [[gnu::packed]] EndOfCentralDirectory { | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> write(Core::Stream::Stream& stream) const |     ErrorOr<void> write(AK::Stream& stream) const | ||||||
|     { |     { | ||||||
|         auto write_value = [&stream](auto value) { |         auto write_value = [&stream](auto value) { | ||||||
|             return stream.write_entire_buffer({ &value, sizeof(value) }); |             return stream.write_entire_buffer({ &value, sizeof(value) }); | ||||||
|  | @ -141,7 +141,7 @@ struct [[gnu::packed]] CentralDirectoryRecord { | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> write(Core::Stream::Stream& stream) const |     ErrorOr<void> write(AK::Stream& stream) const | ||||||
|     { |     { | ||||||
|         auto write_value = [&stream](auto value) { |         auto write_value = [&stream](auto value) { | ||||||
|             return stream.write_entire_buffer({ &value, sizeof(value) }); |             return stream.write_entire_buffer({ &value, sizeof(value) }); | ||||||
|  | @ -210,7 +210,7 @@ struct [[gnu::packed]] LocalFileHeader { | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> write(Core::Stream::Stream& stream) const |     ErrorOr<void> write(AK::Stream& stream) const | ||||||
|     { |     { | ||||||
|         auto write_value = [&stream](auto value) { |         auto write_value = [&stream](auto value) { | ||||||
|             return stream.write_entire_buffer({ &value, sizeof(value) }); |             return stream.write_entire_buffer({ &value, sizeof(value) }); | ||||||
|  | @ -267,13 +267,13 @@ private: | ||||||
| 
 | 
 | ||||||
| class ZipOutputStream { | class ZipOutputStream { | ||||||
| public: | public: | ||||||
|     ZipOutputStream(NonnullOwnPtr<Core::Stream::Stream>); |     ZipOutputStream(NonnullOwnPtr<AK::Stream>); | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> add_member(ZipMember const&); |     ErrorOr<void> add_member(ZipMember const&); | ||||||
|     ErrorOr<void> finish(); |     ErrorOr<void> finish(); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     NonnullOwnPtr<Core::Stream::Stream> m_stream; |     NonnullOwnPtr<AK::Stream> m_stream; | ||||||
|     Vector<ZipMember> m_members; |     Vector<ZipMember> m_members; | ||||||
| 
 | 
 | ||||||
|     bool m_finished { false }; |     bool m_finished { false }; | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace Audio { | namespace Audio { | ||||||
| 
 | 
 | ||||||
| FlacLoaderPlugin::FlacLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream) | FlacLoaderPlugin::FlacLoaderPlugin(NonnullOwnPtr<SeekableStream> stream) | ||||||
|     : LoaderPlugin(move(stream)) |     : LoaderPlugin(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  | @ -60,7 +60,7 @@ MaybeLoaderError FlacLoaderPlugin::initialize() | ||||||
| // 11.5 STREAM
 | // 11.5 STREAM
 | ||||||
| MaybeLoaderError FlacLoaderPlugin::parse_header() | MaybeLoaderError FlacLoaderPlugin::parse_header() | ||||||
| { | { | ||||||
|     auto bit_input = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*m_stream))); |     auto bit_input = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*m_stream))); | ||||||
| 
 | 
 | ||||||
|     // A mixture of VERIFY and the non-crashing TRY().
 |     // A mixture of VERIFY and the non-crashing TRY().
 | ||||||
| #define FLAC_VERIFY(check, category, msg)                                                                                                     \ | #define FLAC_VERIFY(check, category, msg)                                                                                                     \ | ||||||
|  | @ -79,7 +79,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() | ||||||
|     auto streaminfo = TRY(next_meta_block(*bit_input)); |     auto streaminfo = TRY(next_meta_block(*bit_input)); | ||||||
|     FLAC_VERIFY(streaminfo.type == FlacMetadataBlockType::STREAMINFO, LoaderError::Category::Format, "First block must be STREAMINFO"); |     FLAC_VERIFY(streaminfo.type == FlacMetadataBlockType::STREAMINFO, LoaderError::Category::Format, "First block must be STREAMINFO"); | ||||||
|     auto streaminfo_data_memory = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(streaminfo.data.bytes())); |     auto streaminfo_data_memory = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(streaminfo.data.bytes())); | ||||||
|     auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*streaminfo_data_memory))); |     auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*streaminfo_data_memory))); | ||||||
| 
 | 
 | ||||||
|     // 11.10 METADATA_BLOCK_STREAMINFO
 |     // 11.10 METADATA_BLOCK_STREAMINFO
 | ||||||
|     m_min_block_size = LOADER_TRY(streaminfo_data->read_bits<u16>(16)); |     m_min_block_size = LOADER_TRY(streaminfo_data->read_bits<u16>(16)); | ||||||
|  | @ -150,7 +150,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() | ||||||
| MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) | MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) | ||||||
| { | { | ||||||
|     auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); |     auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); | ||||||
|     auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream))); |     auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream))); | ||||||
| 
 | 
 | ||||||
|     PictureData picture {}; |     PictureData picture {}; | ||||||
| 
 | 
 | ||||||
|  | @ -159,12 +159,12 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) | ||||||
|     auto const mime_string_length = LOADER_TRY(picture_block_bytes->read_bits(32)); |     auto const mime_string_length = LOADER_TRY(picture_block_bytes->read_bits(32)); | ||||||
|     // Note: We are seeking before reading the value to ensure that we stayed inside buffer's size.
 |     // Note: We are seeking before reading the value to ensure that we stayed inside buffer's size.
 | ||||||
|     auto offset_before_seeking = memory_stream->offset(); |     auto offset_before_seeking = memory_stream->offset(); | ||||||
|     LOADER_TRY(memory_stream->seek(mime_string_length, Core::Stream::SeekMode::FromCurrentPosition)); |     LOADER_TRY(memory_stream->seek(mime_string_length, SeekMode::FromCurrentPosition)); | ||||||
|     picture.mime_string = { block.data.bytes().data() + offset_before_seeking, (size_t)mime_string_length }; |     picture.mime_string = { block.data.bytes().data() + offset_before_seeking, (size_t)mime_string_length }; | ||||||
| 
 | 
 | ||||||
|     auto const description_string_length = LOADER_TRY(picture_block_bytes->read_bits(32)); |     auto const description_string_length = LOADER_TRY(picture_block_bytes->read_bits(32)); | ||||||
|     offset_before_seeking = memory_stream->offset(); |     offset_before_seeking = memory_stream->offset(); | ||||||
|     LOADER_TRY(memory_stream->seek(description_string_length, Core::Stream::SeekMode::FromCurrentPosition)); |     LOADER_TRY(memory_stream->seek(description_string_length, SeekMode::FromCurrentPosition)); | ||||||
|     picture.description_string = Vector<u32> { Span<u32> { reinterpret_cast<u32*>(block.data.bytes().data() + offset_before_seeking), (size_t)description_string_length } }; |     picture.description_string = Vector<u32> { Span<u32> { reinterpret_cast<u32*>(block.data.bytes().data() + offset_before_seeking), (size_t)description_string_length } }; | ||||||
| 
 | 
 | ||||||
|     picture.width = LOADER_TRY(picture_block_bytes->read_bits(32)); |     picture.width = LOADER_TRY(picture_block_bytes->read_bits(32)); | ||||||
|  | @ -175,7 +175,7 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) | ||||||
| 
 | 
 | ||||||
|     auto const picture_size = LOADER_TRY(picture_block_bytes->read_bits(32)); |     auto const picture_size = LOADER_TRY(picture_block_bytes->read_bits(32)); | ||||||
|     offset_before_seeking = memory_stream->offset(); |     offset_before_seeking = memory_stream->offset(); | ||||||
|     LOADER_TRY(memory_stream->seek(picture_size, Core::Stream::SeekMode::FromCurrentPosition)); |     LOADER_TRY(memory_stream->seek(picture_size, SeekMode::FromCurrentPosition)); | ||||||
|     picture.data = Vector<u8> { Span<u8> { block.data.bytes().data() + offset_before_seeking, (size_t)picture_size } }; |     picture.data = Vector<u8> { Span<u8> { block.data.bytes().data() + offset_before_seeking, (size_t)picture_size } }; | ||||||
| 
 | 
 | ||||||
|     m_pictures.append(move(picture)); |     m_pictures.append(move(picture)); | ||||||
|  | @ -187,7 +187,7 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) | ||||||
| MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block) | MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block) | ||||||
| { | { | ||||||
|     auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); |     auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); | ||||||
|     auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream))); |     auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*memory_stream))); | ||||||
|     for (size_t i = 0; i < block.length / 18; ++i) { |     for (size_t i = 0; i < block.length / 18; ++i) { | ||||||
|         // 11.14. SEEKPOINT
 |         // 11.14. SEEKPOINT
 | ||||||
|         FlacSeekPoint seekpoint { |         FlacSeekPoint seekpoint { | ||||||
|  | @ -259,7 +259,7 @@ MaybeLoaderError FlacLoaderPlugin::seek(int int_sample_index) | ||||||
|     // No seektable or no fitting entry: Perform normal forward read
 |     // No seektable or no fitting entry: Perform normal forward read
 | ||||||
|     if (!maybe_target_seekpoint.has_value()) { |     if (!maybe_target_seekpoint.has_value()) { | ||||||
|         if (sample_index < m_loaded_samples) { |         if (sample_index < m_loaded_samples) { | ||||||
|             LOADER_TRY(m_stream->seek(m_data_start_location, Core::Stream::SeekMode::SetPosition)); |             LOADER_TRY(m_stream->seek(m_data_start_location, SeekMode::SetPosition)); | ||||||
|             m_loaded_samples = 0; |             m_loaded_samples = 0; | ||||||
|         } |         } | ||||||
|         auto to_read = sample_index - m_loaded_samples; |         auto to_read = sample_index - m_loaded_samples; | ||||||
|  | @ -279,7 +279,7 @@ MaybeLoaderError FlacLoaderPlugin::seek(int int_sample_index) | ||||||
| 
 | 
 | ||||||
|         dbgln_if(AFLACLOADER_DEBUG, "Seeking to seektable: sample index {}, byte offset {}, sample count {}", target_seekpoint.sample_index, target_seekpoint.byte_offset, target_seekpoint.num_samples); |         dbgln_if(AFLACLOADER_DEBUG, "Seeking to seektable: sample index {}, byte offset {}, sample count {}", target_seekpoint.sample_index, target_seekpoint.byte_offset, target_seekpoint.num_samples); | ||||||
|         auto position = target_seekpoint.byte_offset + m_data_start_location; |         auto position = target_seekpoint.byte_offset + m_data_start_location; | ||||||
|         if (m_stream->seek(static_cast<i64>(position), Core::Stream::SeekMode::SetPosition).is_error()) |         if (m_stream->seek(static_cast<i64>(position), SeekMode::SetPosition).is_error()) | ||||||
|             return LoaderError { LoaderError::Category::IO, m_loaded_samples, DeprecatedString::formatted("Invalid seek position {}", position) }; |             return LoaderError { LoaderError::Category::IO, m_loaded_samples, DeprecatedString::formatted("Invalid seek position {}", position) }; | ||||||
| 
 | 
 | ||||||
|         auto remaining_samples_after_seekpoint = sample_index - m_data_start_location; |         auto remaining_samples_after_seekpoint = sample_index - m_data_start_location; | ||||||
|  | @ -333,7 +333,7 @@ MaybeLoaderError FlacLoaderPlugin::next_frame(Span<Sample> target_vector) | ||||||
|         }                                                                                                                                         \ |         }                                                                                                                                         \ | ||||||
|     } while (0) |     } while (0) | ||||||
| 
 | 
 | ||||||
|     auto bit_stream = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*m_stream))); |     auto bit_stream = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*m_stream))); | ||||||
| 
 | 
 | ||||||
|     // TODO: Check the CRC-16 checksum (and others) by keeping track of read data
 |     // TODO: Check the CRC-16 checksum (and others) by keeping track of read data
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -47,7 +47,7 @@ ALWAYS_INLINE ErrorOr<i32> decode_unsigned_exp_golomb(u8 order, BigEndianInputBi | ||||||
| //      https://datatracker.ietf.org/doc/html/draft-ietf-cellar-flac-03 (newer IETF draft that uses incompatible numberings and names)
 | //      https://datatracker.ietf.org/doc/html/draft-ietf-cellar-flac-03 (newer IETF draft that uses incompatible numberings and names)
 | ||||||
| class FlacLoaderPlugin : public LoaderPlugin { | class FlacLoaderPlugin : public LoaderPlugin { | ||||||
| public: | public: | ||||||
|     explicit FlacLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream); |     explicit FlacLoaderPlugin(NonnullOwnPtr<SeekableStream> stream); | ||||||
|     virtual ~FlacLoaderPlugin() override = default; |     virtual ~FlacLoaderPlugin() override = default; | ||||||
| 
 | 
 | ||||||
|     static Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> create(StringView path); |     static Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> create(StringView path); | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace Audio { | namespace Audio { | ||||||
| 
 | 
 | ||||||
| LoaderPlugin::LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream) | LoaderPlugin::LoaderPlugin(NonnullOwnPtr<SeekableStream> stream) | ||||||
|     : m_stream(move(stream)) |     : m_stream(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ using MaybeLoaderError = Result<void, LoaderError>; | ||||||
| 
 | 
 | ||||||
| class LoaderPlugin { | class LoaderPlugin { | ||||||
| public: | public: | ||||||
|     explicit LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream); |     explicit LoaderPlugin(NonnullOwnPtr<SeekableStream> stream); | ||||||
|     virtual ~LoaderPlugin() = default; |     virtual ~LoaderPlugin() = default; | ||||||
| 
 | 
 | ||||||
|     virtual LoaderSamples get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) = 0; |     virtual LoaderSamples get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) = 0; | ||||||
|  | @ -58,7 +58,7 @@ public: | ||||||
|     Vector<PictureData> const& pictures() const { return m_pictures; }; |     Vector<PictureData> const& pictures() const { return m_pictures; }; | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
|     NonnullOwnPtr<Core::Stream::SeekableStream> m_stream; |     NonnullOwnPtr<SeekableStream> m_stream; | ||||||
| 
 | 
 | ||||||
|     Vector<PictureData> m_pictures; |     Vector<PictureData> m_pictures; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ namespace Audio { | ||||||
| DSP::MDCT<12> MP3LoaderPlugin::s_mdct_12; | DSP::MDCT<12> MP3LoaderPlugin::s_mdct_12; | ||||||
| DSP::MDCT<36> MP3LoaderPlugin::s_mdct_36; | DSP::MDCT<36> MP3LoaderPlugin::s_mdct_36; | ||||||
| 
 | 
 | ||||||
| MP3LoaderPlugin::MP3LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream) | MP3LoaderPlugin::MP3LoaderPlugin(NonnullOwnPtr<SeekableStream> stream) | ||||||
|     : LoaderPlugin(move(stream)) |     : LoaderPlugin(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  | @ -41,7 +41,7 @@ Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(Byte | ||||||
| 
 | 
 | ||||||
| MaybeLoaderError MP3LoaderPlugin::initialize() | MaybeLoaderError MP3LoaderPlugin::initialize() | ||||||
| { | { | ||||||
|     m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*m_stream))); |     m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*m_stream))); | ||||||
| 
 | 
 | ||||||
|     TRY(synchronize()); |     TRY(synchronize()); | ||||||
| 
 | 
 | ||||||
|  | @ -55,7 +55,7 @@ MaybeLoaderError MP3LoaderPlugin::initialize() | ||||||
| 
 | 
 | ||||||
|     TRY(build_seek_table()); |     TRY(build_seek_table()); | ||||||
| 
 | 
 | ||||||
|     LOADER_TRY(m_stream->seek(0, Core::Stream::SeekMode::SetPosition)); |     LOADER_TRY(m_stream->seek(0, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
|  | @ -76,7 +76,7 @@ MaybeLoaderError MP3LoaderPlugin::seek(int const position) | ||||||
| { | { | ||||||
|     for (auto const& seek_entry : m_seek_table) { |     for (auto const& seek_entry : m_seek_table) { | ||||||
|         if (seek_entry.get<1>() >= position) { |         if (seek_entry.get<1>() >= position) { | ||||||
|             LOADER_TRY(m_stream->seek(seek_entry.get<0>(), Core::Stream::SeekMode::SetPosition)); |             LOADER_TRY(m_stream->seek(seek_entry.get<0>(), SeekMode::SetPosition)); | ||||||
|             m_loaded_samples = seek_entry.get<1>(); |             m_loaded_samples = seek_entry.get<1>(); | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
|  | @ -140,7 +140,7 @@ MaybeLoaderError MP3LoaderPlugin::build_seek_table() | ||||||
|     m_bitstream->align_to_byte_boundary(); |     m_bitstream->align_to_byte_boundary(); | ||||||
| 
 | 
 | ||||||
|     while (!synchronize().is_error()) { |     while (!synchronize().is_error()) { | ||||||
|         auto const frame_pos = -2 + LOADER_TRY(m_stream->seek(0, Core::Stream::SeekMode::FromCurrentPosition)); |         auto const frame_pos = -2 + LOADER_TRY(m_stream->seek(0, SeekMode::FromCurrentPosition)); | ||||||
| 
 | 
 | ||||||
|         auto error_or_header = read_header(); |         auto error_or_header = read_header(); | ||||||
|         if (error_or_header.is_error() || error_or_header.value().id != 1 || error_or_header.value().layer != 3) { |         if (error_or_header.is_error() || error_or_header.value().id != 1 || error_or_header.value().layer != 3) { | ||||||
|  | @ -152,7 +152,7 @@ MaybeLoaderError MP3LoaderPlugin::build_seek_table() | ||||||
|         if (frame_count % 10 == 0) |         if (frame_count % 10 == 0) | ||||||
|             m_seek_table.append({ frame_pos, sample_count }); |             m_seek_table.append({ frame_pos, sample_count }); | ||||||
| 
 | 
 | ||||||
|         LOADER_TRY(m_stream->seek(error_or_header.value().frame_size - 6, Core::Stream::SeekMode::FromCurrentPosition)); |         LOADER_TRY(m_stream->seek(error_or_header.value().frame_size - 6, SeekMode::FromCurrentPosition)); | ||||||
| 
 | 
 | ||||||
|         // TODO: This is just here to clear the bitstream buffer.
 |         // TODO: This is just here to clear the bitstream buffer.
 | ||||||
|         // Bitstream should have a method to sync its state to the underlying stream.
 |         // Bitstream should have a method to sync its state to the underlying stream.
 | ||||||
|  | @ -242,7 +242,7 @@ ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_frame_data(MP3::Header | ||||||
| 
 | 
 | ||||||
|     TRY(m_bit_reservoir.discard(old_reservoir_size - frame.main_data_begin)); |     TRY(m_bit_reservoir.discard(old_reservoir_size - frame.main_data_begin)); | ||||||
| 
 | 
 | ||||||
|     auto reservoir_stream = TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(m_bit_reservoir))); |     auto reservoir_stream = TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(m_bit_reservoir))); | ||||||
| 
 | 
 | ||||||
|     for (size_t granule_index = 0; granule_index < 2; granule_index++) { |     for (size_t granule_index = 0; granule_index < 2; granule_index++) { | ||||||
|         for (size_t channel_index = 0; channel_index < header.channel_count(); channel_index++) { |         for (size_t channel_index = 0; channel_index < header.channel_count(); channel_index++) { | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ struct ScaleFactorBand; | ||||||
| 
 | 
 | ||||||
| class MP3LoaderPlugin : public LoaderPlugin { | class MP3LoaderPlugin : public LoaderPlugin { | ||||||
| public: | public: | ||||||
|     explicit MP3LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream); |     explicit MP3LoaderPlugin(NonnullOwnPtr<SeekableStream> stream); | ||||||
|     virtual ~MP3LoaderPlugin() = default; |     virtual ~MP3LoaderPlugin() = default; | ||||||
| 
 | 
 | ||||||
|     static Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> create(StringView path); |     static Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> create(StringView path); | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ namespace Audio { | ||||||
| 
 | 
 | ||||||
| static constexpr size_t const maximum_wav_size = 1 * GiB; // FIXME: is there a more appropriate size limit?
 | static constexpr size_t const maximum_wav_size = 1 * GiB; // FIXME: is there a more appropriate size limit?
 | ||||||
| 
 | 
 | ||||||
| WavLoaderPlugin::WavLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream) | WavLoaderPlugin::WavLoaderPlugin(NonnullOwnPtr<SeekableStream> stream) | ||||||
|     : LoaderPlugin(move(stream)) |     : LoaderPlugin(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  | @ -51,7 +51,7 @@ MaybeLoaderError WavLoaderPlugin::initialize() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template<typename SampleReader> | template<typename SampleReader> | ||||||
| MaybeLoaderError WavLoaderPlugin::read_samples_from_stream(Core::Stream::Stream& stream, SampleReader read_sample, FixedArray<Sample>& samples) const | MaybeLoaderError WavLoaderPlugin::read_samples_from_stream(AK::Stream& stream, SampleReader read_sample, FixedArray<Sample>& samples) const | ||||||
| { | { | ||||||
|     switch (m_num_channels) { |     switch (m_num_channels) { | ||||||
|     case 1: |     case 1: | ||||||
|  | @ -72,7 +72,7 @@ MaybeLoaderError WavLoaderPlugin::read_samples_from_stream(Core::Stream::Stream& | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // There's no i24 type + we need to do the endianness conversion manually anyways.
 | // There's no i24 type + we need to do the endianness conversion manually anyways.
 | ||||||
| static ErrorOr<double> read_sample_int24(Core::Stream::Stream& stream) | static ErrorOr<double> read_sample_int24(AK::Stream& stream) | ||||||
| { | { | ||||||
|     u8 byte = 0; |     u8 byte = 0; | ||||||
|     TRY(stream.read(Bytes { &byte, 1 })); |     TRY(stream.read(Bytes { &byte, 1 })); | ||||||
|  | @ -93,7 +93,7 @@ static ErrorOr<double> read_sample_int24(Core::Stream::Stream& stream) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template<typename T> | template<typename T> | ||||||
| static ErrorOr<double> read_sample(Core::Stream::Stream& stream) | static ErrorOr<double> read_sample(AK::Stream& stream) | ||||||
| { | { | ||||||
|     T sample { 0 }; |     T sample { 0 }; | ||||||
|     TRY(stream.read(Bytes { &sample, sizeof(T) })); |     TRY(stream.read(Bytes { &sample, sizeof(T) })); | ||||||
|  | @ -177,7 +177,7 @@ MaybeLoaderError WavLoaderPlugin::seek(int sample_index) | ||||||
| 
 | 
 | ||||||
|     size_t sample_offset = m_byte_offset_of_data_samples + static_cast<size_t>(sample_index * m_num_channels * (pcm_bits_per_sample(m_sample_format) / 8)); |     size_t sample_offset = m_byte_offset_of_data_samples + static_cast<size_t>(sample_index * m_num_channels * (pcm_bits_per_sample(m_sample_format) / 8)); | ||||||
| 
 | 
 | ||||||
|     LOADER_TRY(m_stream->seek(sample_offset, Core::Stream::SeekMode::SetPosition)); |     LOADER_TRY(m_stream->seek(sample_offset, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     m_loaded_samples = sample_index; |     m_loaded_samples = sample_index; | ||||||
|     return {}; |     return {}; | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ static constexpr unsigned const WAVE_FORMAT_EXTENSIBLE = 0xFFFE; // Determined b | ||||||
| // Parses and reads audio data from a WAV file.
 | // Parses and reads audio data from a WAV file.
 | ||||||
| class WavLoaderPlugin : public LoaderPlugin { | class WavLoaderPlugin : public LoaderPlugin { | ||||||
| public: | public: | ||||||
|     explicit WavLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream); |     explicit WavLoaderPlugin(NonnullOwnPtr<SeekableStream> stream); | ||||||
|     static Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> create(StringView path); |     static Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> create(StringView path); | ||||||
|     static Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> create(Bytes buffer); |     static Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> create(Bytes buffer); | ||||||
| 
 | 
 | ||||||
|  | @ -55,7 +55,7 @@ private: | ||||||
| 
 | 
 | ||||||
|     LoaderSamples samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const; |     LoaderSamples samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const; | ||||||
|     template<typename SampleReader> |     template<typename SampleReader> | ||||||
|     MaybeLoaderError read_samples_from_stream(Core::Stream::Stream& stream, SampleReader read_sample, FixedArray<Sample>& samples) const; |     MaybeLoaderError read_samples_from_stream(AK::Stream& stream, SampleReader read_sample, FixedArray<Sample>& samples) const; | ||||||
| 
 | 
 | ||||||
|     u32 m_sample_rate { 0 }; |     u32 m_sample_rate { 0 }; | ||||||
|     u16 m_num_channels { 0 }; |     u16 m_num_channels { 0 }; | ||||||
|  |  | ||||||
|  | @ -13,8 +13,8 @@ | ||||||
| 
 | 
 | ||||||
| namespace Compress { | namespace Compress { | ||||||
| 
 | 
 | ||||||
|  | using AK::Stream; | ||||||
| using Core::Stream::LittleEndianInputBitStream; | using Core::Stream::LittleEndianInputBitStream; | ||||||
| using Core::Stream::Stream; |  | ||||||
| 
 | 
 | ||||||
| class BrotliDecompressionStream : public Stream { | class BrotliDecompressionStream : public Stream { | ||||||
| public: | public: | ||||||
|  |  | ||||||
|  | @ -188,13 +188,13 @@ ErrorOr<bool> DeflateDecompressor::UncompressedBlock::try_read_more() | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<NonnullOwnPtr<DeflateDecompressor>> DeflateDecompressor::construct(MaybeOwned<Core::Stream::Stream> stream) | ErrorOr<NonnullOwnPtr<DeflateDecompressor>> DeflateDecompressor::construct(MaybeOwned<AK::Stream> stream) | ||||||
| { | { | ||||||
|     auto output_buffer = TRY(CircularBuffer::create_empty(32 * KiB)); |     auto output_buffer = TRY(CircularBuffer::create_empty(32 * KiB)); | ||||||
|     return TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateDecompressor(move(stream), move(output_buffer)))); |     return TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateDecompressor(move(stream), move(output_buffer)))); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| DeflateDecompressor::DeflateDecompressor(MaybeOwned<Core::Stream::Stream> stream, CircularBuffer output_buffer) | DeflateDecompressor::DeflateDecompressor(MaybeOwned<AK::Stream> stream, CircularBuffer output_buffer) | ||||||
|     : m_input_stream(make<Core::Stream::LittleEndianInputBitStream>(move(stream))) |     : m_input_stream(make<Core::Stream::LittleEndianInputBitStream>(move(stream))) | ||||||
|     , m_output_buffer(move(output_buffer)) |     , m_output_buffer(move(output_buffer)) | ||||||
| { | { | ||||||
|  | @ -446,7 +446,7 @@ ErrorOr<void> DeflateDecompressor::decode_codes(CanonicalCode& literal_code, Opt | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<NonnullOwnPtr<DeflateCompressor>> DeflateCompressor::construct(MaybeOwned<Core::Stream::Stream> stream, CompressionLevel compression_level) | ErrorOr<NonnullOwnPtr<DeflateCompressor>> DeflateCompressor::construct(MaybeOwned<AK::Stream> stream, CompressionLevel compression_level) | ||||||
| { | { | ||||||
|     auto bit_stream = TRY(Core::Stream::LittleEndianOutputBitStream::construct(move(stream))); |     auto bit_stream = TRY(Core::Stream::LittleEndianOutputBitStream::construct(move(stream))); | ||||||
|     auto deflate_compressor = TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateCompressor(move(bit_stream), compression_level))); |     auto deflate_compressor = TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateCompressor(move(bit_stream), compression_level))); | ||||||
|  | @ -1017,7 +1017,7 @@ ErrorOr<void> DeflateCompressor::final_flush() | ||||||
| ErrorOr<ByteBuffer> DeflateCompressor::compress_all(ReadonlyBytes bytes, CompressionLevel compression_level) | ErrorOr<ByteBuffer> DeflateCompressor::compress_all(ReadonlyBytes bytes, CompressionLevel compression_level) | ||||||
| { | { | ||||||
|     auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>()); |     auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>()); | ||||||
|     auto deflate_stream = TRY(DeflateCompressor::construct(MaybeOwned<Core::Stream::Stream>(*output_stream), compression_level)); |     auto deflate_stream = TRY(DeflateCompressor::construct(MaybeOwned<AK::Stream>(*output_stream), compression_level)); | ||||||
| 
 | 
 | ||||||
|     TRY(deflate_stream->write_entire_buffer(bytes)); |     TRY(deflate_stream->write_entire_buffer(bytes)); | ||||||
|     TRY(deflate_stream->final_flush()); |     TRY(deflate_stream->final_flush()); | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ private: | ||||||
|     Array<u16, 288> m_bit_code_lengths {}; |     Array<u16, 288> m_bit_code_lengths {}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class DeflateDecompressor final : public Core::Stream::Stream { | class DeflateDecompressor final : public AK::Stream { | ||||||
| private: | private: | ||||||
|     class CompressedBlock { |     class CompressedBlock { | ||||||
|     public: |     public: | ||||||
|  | @ -74,7 +74,7 @@ public: | ||||||
|     friend CompressedBlock; |     friend CompressedBlock; | ||||||
|     friend UncompressedBlock; |     friend UncompressedBlock; | ||||||
| 
 | 
 | ||||||
|     static ErrorOr<NonnullOwnPtr<DeflateDecompressor>> construct(MaybeOwned<Core::Stream::Stream> stream); |     static ErrorOr<NonnullOwnPtr<DeflateDecompressor>> construct(MaybeOwned<AK::Stream> stream); | ||||||
|     ~DeflateDecompressor(); |     ~DeflateDecompressor(); | ||||||
| 
 | 
 | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|  | @ -86,7 +86,7 @@ public: | ||||||
|     static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes); |     static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     DeflateDecompressor(MaybeOwned<Core::Stream::Stream> stream, CircularBuffer buffer); |     DeflateDecompressor(MaybeOwned<AK::Stream> stream, CircularBuffer buffer); | ||||||
| 
 | 
 | ||||||
|     ErrorOr<u32> decode_length(u32); |     ErrorOr<u32> decode_length(u32); | ||||||
|     ErrorOr<u32> decode_distance(u32); |     ErrorOr<u32> decode_distance(u32); | ||||||
|  | @ -104,7 +104,7 @@ private: | ||||||
|     CircularBuffer m_output_buffer; |     CircularBuffer m_output_buffer; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class DeflateCompressor final : public Core::Stream::Stream { | class DeflateCompressor final : public AK::Stream { | ||||||
| public: | public: | ||||||
|     static constexpr size_t block_size = 32 * KiB - 1; // TODO: this can theoretically be increased to 64 KiB - 2
 |     static constexpr size_t block_size = 32 * KiB - 1; // TODO: this can theoretically be increased to 64 KiB - 2
 | ||||||
|     static constexpr size_t window_size = block_size * 2; |     static constexpr size_t window_size = block_size * 2; | ||||||
|  | @ -139,7 +139,7 @@ public: | ||||||
|         BEST // WARNING: this one can take an unreasonable amount of time!
 |         BEST // WARNING: this one can take an unreasonable amount of time!
 | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     static ErrorOr<NonnullOwnPtr<DeflateCompressor>> construct(MaybeOwned<Core::Stream::Stream>, CompressionLevel = CompressionLevel::GOOD); |     static ErrorOr<NonnullOwnPtr<DeflateCompressor>> construct(MaybeOwned<AK::Stream>, CompressionLevel = CompressionLevel::GOOD); | ||||||
|     ~DeflateCompressor(); |     ~DeflateCompressor(); | ||||||
| 
 | 
 | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|  |  | ||||||
|  | @ -38,9 +38,9 @@ bool BlockHeader::supported_by_implementation() const | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<NonnullOwnPtr<GzipDecompressor::Member>> GzipDecompressor::Member::construct(BlockHeader header, Core::Stream::Stream& stream) | ErrorOr<NonnullOwnPtr<GzipDecompressor::Member>> GzipDecompressor::Member::construct(BlockHeader header, AK::Stream& stream) | ||||||
| { | { | ||||||
|     auto deflate_stream = TRY(DeflateDecompressor::construct(MaybeOwned<Core::Stream::Stream>(stream))); |     auto deflate_stream = TRY(DeflateDecompressor::construct(MaybeOwned<AK::Stream>(stream))); | ||||||
|     return TRY(adopt_nonnull_own_or_enomem(new (nothrow) Member(header, move(deflate_stream)))); |     return TRY(adopt_nonnull_own_or_enomem(new (nothrow) Member(header, move(deflate_stream)))); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -50,7 +50,7 @@ GzipDecompressor::Member::Member(BlockHeader header, NonnullOwnPtr<DeflateDecomp | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GzipDecompressor::GzipDecompressor(NonnullOwnPtr<Core::Stream::Stream> stream) | GzipDecompressor::GzipDecompressor(NonnullOwnPtr<AK::Stream> stream) | ||||||
|     : m_input_stream(move(stream)) |     : m_input_stream(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  | @ -186,7 +186,7 @@ ErrorOr<size_t> GzipDecompressor::write(ReadonlyBytes) | ||||||
|     return Error::from_errno(EBADF); |     return Error::from_errno(EBADF); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GzipCompressor::GzipCompressor(MaybeOwned<Core::Stream::Stream> stream) | GzipCompressor::GzipCompressor(MaybeOwned<AK::Stream> stream) | ||||||
|     : m_output_stream(move(stream)) |     : m_output_stream(move(stream)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  | @ -236,7 +236,7 @@ void GzipCompressor::close() | ||||||
| ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes) | ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes) | ||||||
| { | { | ||||||
|     auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>()); |     auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>()); | ||||||
|     GzipCompressor gzip_stream { MaybeOwned<Core::Stream::Stream>(*output_stream) }; |     GzipCompressor gzip_stream { MaybeOwned<AK::Stream>(*output_stream) }; | ||||||
| 
 | 
 | ||||||
|     TRY(gzip_stream.write_entire_buffer(bytes)); |     TRY(gzip_stream.write_entire_buffer(bytes)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -38,9 +38,9 @@ struct Flags { | ||||||
|     static constexpr u8 MAX = FTEXT | FHCRC | FEXTRA | FNAME | FCOMMENT; |     static constexpr u8 MAX = FTEXT | FHCRC | FEXTRA | FNAME | FCOMMENT; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class GzipDecompressor final : public Core::Stream::Stream { | class GzipDecompressor final : public AK::Stream { | ||||||
| public: | public: | ||||||
|     GzipDecompressor(NonnullOwnPtr<Core::Stream::Stream>); |     GzipDecompressor(NonnullOwnPtr<AK::Stream>); | ||||||
|     ~GzipDecompressor(); |     ~GzipDecompressor(); | ||||||
| 
 | 
 | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|  | @ -56,7 +56,7 @@ public: | ||||||
| private: | private: | ||||||
|     class Member { |     class Member { | ||||||
|     public: |     public: | ||||||
|         static ErrorOr<NonnullOwnPtr<Member>> construct(BlockHeader header, Core::Stream::Stream&); |         static ErrorOr<NonnullOwnPtr<Member>> construct(BlockHeader header, AK::Stream&); | ||||||
| 
 | 
 | ||||||
|         BlockHeader m_header; |         BlockHeader m_header; | ||||||
|         NonnullOwnPtr<DeflateDecompressor> m_stream; |         NonnullOwnPtr<DeflateDecompressor> m_stream; | ||||||
|  | @ -70,7 +70,7 @@ private: | ||||||
|     Member const& current_member() const { return *m_current_member; } |     Member const& current_member() const { return *m_current_member; } | ||||||
|     Member& current_member() { return *m_current_member; } |     Member& current_member() { return *m_current_member; } | ||||||
| 
 | 
 | ||||||
|     NonnullOwnPtr<Core::Stream::Stream> m_input_stream; |     NonnullOwnPtr<AK::Stream> m_input_stream; | ||||||
|     u8 m_partial_header[sizeof(BlockHeader)]; |     u8 m_partial_header[sizeof(BlockHeader)]; | ||||||
|     size_t m_partial_header_offset { 0 }; |     size_t m_partial_header_offset { 0 }; | ||||||
|     OwnPtr<Member> m_current_member {}; |     OwnPtr<Member> m_current_member {}; | ||||||
|  | @ -78,9 +78,9 @@ private: | ||||||
|     bool m_eof { false }; |     bool m_eof { false }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class GzipCompressor final : public Core::Stream::Stream { | class GzipCompressor final : public AK::Stream { | ||||||
| public: | public: | ||||||
|     GzipCompressor(MaybeOwned<Core::Stream::Stream>); |     GzipCompressor(MaybeOwned<AK::Stream>); | ||||||
| 
 | 
 | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|     virtual ErrorOr<size_t> write(ReadonlyBytes) override; |     virtual ErrorOr<size_t> write(ReadonlyBytes) override; | ||||||
|  | @ -91,7 +91,7 @@ public: | ||||||
|     static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes); |     static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     MaybeOwned<Core::Stream::Stream> m_output_stream; |     MaybeOwned<AK::Stream> m_output_stream; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -69,7 +69,7 @@ u32 ZlibDecompressor::checksum() | ||||||
|     return m_checksum; |     return m_checksum; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<NonnullOwnPtr<ZlibCompressor>> ZlibCompressor::construct(MaybeOwned<Core::Stream::Stream> stream, ZlibCompressionLevel compression_level) | ErrorOr<NonnullOwnPtr<ZlibCompressor>> ZlibCompressor::construct(MaybeOwned<AK::Stream> stream, ZlibCompressionLevel compression_level) | ||||||
| { | { | ||||||
|     // Zlib only defines Deflate as a compression method.
 |     // Zlib only defines Deflate as a compression method.
 | ||||||
|     auto compression_method = ZlibCompressionMethod::Deflate; |     auto compression_method = ZlibCompressionMethod::Deflate; | ||||||
|  | @ -83,7 +83,7 @@ ErrorOr<NonnullOwnPtr<ZlibCompressor>> ZlibCompressor::construct(MaybeOwned<Core | ||||||
|     return zlib_compressor; |     return zlib_compressor; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ZlibCompressor::ZlibCompressor(MaybeOwned<Core::Stream::Stream> stream, NonnullOwnPtr<Core::Stream::Stream> compressor_stream) | ZlibCompressor::ZlibCompressor(MaybeOwned<AK::Stream> stream, NonnullOwnPtr<AK::Stream> compressor_stream) | ||||||
|     : m_output_stream(move(stream)) |     : m_output_stream(move(stream)) | ||||||
|     , m_compressor(move(compressor_stream)) |     , m_compressor(move(compressor_stream)) | ||||||
| { | { | ||||||
|  | @ -164,7 +164,7 @@ ErrorOr<void> ZlibCompressor::finish() | ||||||
| ErrorOr<ByteBuffer> ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompressionLevel compression_level) | ErrorOr<ByteBuffer> ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompressionLevel compression_level) | ||||||
| { | { | ||||||
|     auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>()); |     auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>()); | ||||||
|     auto zlib_stream = TRY(ZlibCompressor::construct(MaybeOwned<Core::Stream::Stream>(*output_stream), compression_level)); |     auto zlib_stream = TRY(ZlibCompressor::construct(MaybeOwned<AK::Stream>(*output_stream), compression_level)); | ||||||
| 
 | 
 | ||||||
|     TRY(zlib_stream->write_entire_buffer(bytes)); |     TRY(zlib_stream->write_entire_buffer(bytes)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -61,9 +61,9 @@ private: | ||||||
|     ReadonlyBytes m_data_bytes; |     ReadonlyBytes m_data_bytes; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class ZlibCompressor : public Core::Stream::Stream { | class ZlibCompressor : public AK::Stream { | ||||||
| public: | public: | ||||||
|     static ErrorOr<NonnullOwnPtr<ZlibCompressor>> construct(MaybeOwned<Core::Stream::Stream>, ZlibCompressionLevel = ZlibCompressionLevel::Default); |     static ErrorOr<NonnullOwnPtr<ZlibCompressor>> construct(MaybeOwned<AK::Stream>, ZlibCompressionLevel = ZlibCompressionLevel::Default); | ||||||
|     ~ZlibCompressor(); |     ~ZlibCompressor(); | ||||||
| 
 | 
 | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|  | @ -76,12 +76,12 @@ public: | ||||||
|     static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes, ZlibCompressionLevel = ZlibCompressionLevel::Default); |     static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes, ZlibCompressionLevel = ZlibCompressionLevel::Default); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     ZlibCompressor(MaybeOwned<Core::Stream::Stream> stream, NonnullOwnPtr<Core::Stream::Stream> compressor_stream); |     ZlibCompressor(MaybeOwned<AK::Stream> stream, NonnullOwnPtr<AK::Stream> compressor_stream); | ||||||
|     ErrorOr<void> write_header(ZlibCompressionMethod, ZlibCompressionLevel); |     ErrorOr<void> write_header(ZlibCompressionMethod, ZlibCompressionLevel); | ||||||
| 
 | 
 | ||||||
|     bool m_finished { false }; |     bool m_finished { false }; | ||||||
|     MaybeOwned<Core::Stream::Stream> m_output_stream; |     MaybeOwned<AK::Stream> m_output_stream; | ||||||
|     NonnullOwnPtr<Core::Stream::Stream> m_compressor; |     NonnullOwnPtr<AK::Stream> m_compressor; | ||||||
|     Crypto::Checksum::Adler32 m_adler32_checksum; |     Crypto::Checksum::Adler32 m_adler32_checksum; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ namespace Core::Stream { | ||||||
| 
 | 
 | ||||||
| /// A stream wrapper class that allows you to read arbitrary amounts of bits
 | /// A stream wrapper class that allows you to read arbitrary amounts of bits
 | ||||||
| /// in big-endian order from another stream.
 | /// in big-endian order from another stream.
 | ||||||
| class BigEndianInputBitStream : public Stream { | class BigEndianInputBitStream : public AK::Stream { | ||||||
| public: | public: | ||||||
|     static ErrorOr<NonnullOwnPtr<BigEndianInputBitStream>> construct(MaybeOwned<Stream> stream) |     static ErrorOr<NonnullOwnPtr<BigEndianInputBitStream>> construct(MaybeOwned<Stream> stream) | ||||||
|     { |     { | ||||||
|  | @ -131,7 +131,7 @@ private: | ||||||
| 
 | 
 | ||||||
| /// A stream wrapper class that allows you to read arbitrary amounts of bits
 | /// A stream wrapper class that allows you to read arbitrary amounts of bits
 | ||||||
| /// in little-endian order from another stream.
 | /// in little-endian order from another stream.
 | ||||||
| class LittleEndianInputBitStream : public Stream { | class LittleEndianInputBitStream : public AK::Stream { | ||||||
| public: | public: | ||||||
|     static ErrorOr<NonnullOwnPtr<LittleEndianInputBitStream>> construct(MaybeOwned<Stream> stream) |     static ErrorOr<NonnullOwnPtr<LittleEndianInputBitStream>> construct(MaybeOwned<Stream> stream) | ||||||
|     { |     { | ||||||
|  | @ -240,7 +240,7 @@ private: | ||||||
| 
 | 
 | ||||||
| /// A stream wrapper class that allows you to write arbitrary amounts of bits
 | /// A stream wrapper class that allows you to write arbitrary amounts of bits
 | ||||||
| /// in big-endian order to another stream.
 | /// in big-endian order to another stream.
 | ||||||
| class BigEndianOutputBitStream : public Stream { | class BigEndianOutputBitStream : public AK::Stream { | ||||||
| public: | public: | ||||||
|     static ErrorOr<NonnullOwnPtr<BigEndianOutputBitStream>> construct(MaybeOwned<Stream> stream) |     static ErrorOr<NonnullOwnPtr<BigEndianOutputBitStream>> construct(MaybeOwned<Stream> stream) | ||||||
|     { |     { | ||||||
|  | @ -323,7 +323,7 @@ private: | ||||||
| 
 | 
 | ||||||
| /// A stream wrapper class that allows you to write arbitrary amounts of bits
 | /// A stream wrapper class that allows you to write arbitrary amounts of bits
 | ||||||
| /// in little-endian order to another stream.
 | /// in little-endian order to another stream.
 | ||||||
| class LittleEndianOutputBitStream : public Stream { | class LittleEndianOutputBitStream : public AK::Stream { | ||||||
| public: | public: | ||||||
|     static ErrorOr<NonnullOwnPtr<LittleEndianOutputBitStream>> construct(MaybeOwned<Stream> stream) |     static ErrorOr<NonnullOwnPtr<LittleEndianOutputBitStream>> construct(MaybeOwned<Stream> stream) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -176,7 +176,7 @@ ErrorOr<void> ConfigFile::sync() | ||||||
|         return Error::from_errno(ENOENT); |         return Error::from_errno(ENOENT); | ||||||
| 
 | 
 | ||||||
|     TRY(m_file->truncate(0)); |     TRY(m_file->truncate(0)); | ||||||
|     TRY(m_file->seek(0, Stream::SeekMode::SetPosition)); |     TRY(m_file->seek(0, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     for (auto& it : m_groups) { |     for (auto& it : m_groups) { | ||||||
|         TRY(m_file->write(DeprecatedString::formatted("[{}]\n", it.key).bytes())); |         TRY(m_file->write(DeprecatedString::formatted("[{}]\n", it.key).bytes())); | ||||||
|  |  | ||||||
|  | @ -40,7 +40,6 @@ enum class TimerShouldFireWhenNotVisible; | ||||||
| namespace Stream { | namespace Stream { | ||||||
| class File; | class File; | ||||||
| class Socket; | class Socket; | ||||||
| class Stream; |  | ||||||
| class BufferedSocketBase; | class BufferedSocketBase; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <AK/EnumBits.h> | #include <AK/EnumBits.h> | ||||||
| #include <AK/Forward.h> | #include <AK/Forward.h> | ||||||
|  | #include <AK/Stream.h> | ||||||
| #include <LibCore/Object.h> | #include <LibCore/Object.h> | ||||||
| 
 | 
 | ||||||
| namespace Core { | namespace Core { | ||||||
|  | @ -62,12 +63,6 @@ enum class OpenMode : unsigned { | ||||||
|     KeepOnExec = 32, |     KeepOnExec = 32, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| enum class SeekMode { |  | ||||||
|     SetPosition, |  | ||||||
|     FromCurrentPosition, |  | ||||||
|     FromEndPosition, |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| AK_ENUM_BITWISE_OPERATORS(OpenMode) | AK_ENUM_BITWISE_OPERATORS(OpenMode) | ||||||
| 
 | 
 | ||||||
| class IODevice : public Object { | class IODevice : public Object { | ||||||
|  |  | ||||||
|  | @ -49,7 +49,7 @@ private: | ||||||
| 
 | 
 | ||||||
| /// A stream class that allows for writing to an automatically allocating memory area
 | /// A stream class that allows for writing to an automatically allocating memory area
 | ||||||
| /// and reading back the written data afterwards.
 | /// and reading back the written data afterwards.
 | ||||||
| class AllocatingMemoryStream final : public Stream { | class AllocatingMemoryStream final : public AK::Stream { | ||||||
| public: | public: | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|     virtual ErrorOr<size_t> write(ReadonlyBytes) override; |     virtual ErrorOr<size_t> write(ReadonlyBytes) override; | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace Core { | namespace Core { | ||||||
| 
 | 
 | ||||||
| NetworkJob::NetworkJob(Core::Stream::Stream& output_stream) | NetworkJob::NetworkJob(AK::Stream& output_stream) | ||||||
|     : m_output_stream(output_stream) |     : m_output_stream(output_stream) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -52,7 +52,7 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
|     NetworkJob(Core::Stream::Stream&); |     NetworkJob(AK::Stream&); | ||||||
|     void did_finish(NonnullRefPtr<NetworkResponse>&&); |     void did_finish(NonnullRefPtr<NetworkResponse>&&); | ||||||
|     void did_fail(Error); |     void did_fail(Error); | ||||||
|     void did_progress(Optional<u32> total_size, u32 downloaded); |     void did_progress(Optional<u32> total_size, u32 downloaded); | ||||||
|  | @ -61,7 +61,7 @@ protected: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     RefPtr<NetworkResponse> m_response; |     RefPtr<NetworkResponse> m_response; | ||||||
|     Core::Stream::Stream& m_output_stream; |     AK::Stream& m_output_stream; | ||||||
|     Error m_error { Error::None }; |     Error m_error { Error::None }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -15,9 +15,9 @@ namespace Core { | ||||||
| 
 | 
 | ||||||
| HashMap<uid_t, DeprecatedString> ProcessStatisticsReader::s_usernames; | HashMap<uid_t, DeprecatedString> ProcessStatisticsReader::s_usernames; | ||||||
| 
 | 
 | ||||||
| ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(Core::Stream::SeekableStream& proc_all_file, bool include_usernames) | ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(SeekableStream& proc_all_file, bool include_usernames) | ||||||
| { | { | ||||||
|     TRY(proc_all_file.seek(0, Core::Stream::SeekMode::SetPosition)); |     TRY(proc_all_file.seek(0, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     AllProcessesStatistics all_processes_statistics; |     AllProcessesStatistics all_processes_statistics; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -72,7 +72,7 @@ struct AllProcessesStatistics { | ||||||
| 
 | 
 | ||||||
| class ProcessStatisticsReader { | class ProcessStatisticsReader { | ||||||
| public: | public: | ||||||
|     static ErrorOr<AllProcessesStatistics> get_all(Core::Stream::SeekableStream&, bool include_usernames = true); |     static ErrorOr<AllProcessesStatistics> get_all(SeekableStream&, bool include_usernames = true); | ||||||
|     static ErrorOr<AllProcessesStatistics> get_all(bool include_usernames = true); |     static ErrorOr<AllProcessesStatistics> get_all(bool include_usernames = true); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
|  | @ -22,124 +22,6 @@ | ||||||
| 
 | 
 | ||||||
| namespace Core::Stream { | namespace Core::Stream { | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> Stream::read_entire_buffer(Bytes buffer) |  | ||||||
| { |  | ||||||
|     size_t nread = 0; |  | ||||||
|     while (nread < buffer.size()) { |  | ||||||
|         if (is_eof()) |  | ||||||
|             return Error::from_string_literal("Reached end-of-file before filling the entire buffer"); |  | ||||||
| 
 |  | ||||||
|         auto result = read(buffer.slice(nread)); |  | ||||||
|         if (result.is_error()) { |  | ||||||
|             if (result.error().is_errno() && result.error().code() == EINTR) { |  | ||||||
|                 continue; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return result.release_error(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         nread += result.value().size(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return {}; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<ByteBuffer> Stream::read_until_eof(size_t block_size) |  | ||||||
| { |  | ||||||
|     return read_until_eof_impl(block_size); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<ByteBuffer> Stream::read_until_eof_impl(size_t block_size, size_t expected_file_size) |  | ||||||
| { |  | ||||||
|     ByteBuffer data; |  | ||||||
|     data.ensure_capacity(expected_file_size); |  | ||||||
| 
 |  | ||||||
|     size_t total_read = 0; |  | ||||||
|     Bytes buffer; |  | ||||||
|     while (!is_eof()) { |  | ||||||
|         if (buffer.is_empty()) { |  | ||||||
|             buffer = TRY(data.get_bytes_for_writing(block_size)); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         auto nread = TRY(read(buffer)).size(); |  | ||||||
|         total_read += nread; |  | ||||||
|         buffer = buffer.slice(nread); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     data.resize(total_read); |  | ||||||
|     return data; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<void> Stream::discard(size_t discarded_bytes) |  | ||||||
| { |  | ||||||
|     // Note: This was chosen arbitrarily.
 |  | ||||||
|     // Note: This can't be PAGE_SIZE because it is defined to sysconf() on Lagom.
 |  | ||||||
|     constexpr size_t continuous_read_size = 4096; |  | ||||||
| 
 |  | ||||||
|     Array<u8, continuous_read_size> buffer; |  | ||||||
| 
 |  | ||||||
|     while (discarded_bytes > 0) { |  | ||||||
|         if (is_eof()) |  | ||||||
|             return Error::from_string_literal("Reached end-of-file before reading all discarded bytes"); |  | ||||||
| 
 |  | ||||||
|         auto slice = TRY(read(buffer.span().slice(0, min(discarded_bytes, continuous_read_size)))); |  | ||||||
|         discarded_bytes -= slice.size(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return {}; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<void> Stream::write_entire_buffer(ReadonlyBytes buffer) |  | ||||||
| { |  | ||||||
|     size_t nwritten = 0; |  | ||||||
|     while (nwritten < buffer.size()) { |  | ||||||
|         auto result = write(buffer.slice(nwritten)); |  | ||||||
|         if (result.is_error()) { |  | ||||||
|             if (result.error().is_errno() && result.error().code() == EINTR) { |  | ||||||
|                 continue; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return result.release_error(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         nwritten += result.value(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return {}; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<size_t> SeekableStream::tell() const |  | ||||||
| { |  | ||||||
|     // Seek with 0 and SEEK_CUR does not modify anything despite the const_cast,
 |  | ||||||
|     // so it's safe to do this.
 |  | ||||||
|     return const_cast<SeekableStream*>(this)->seek(0, SeekMode::FromCurrentPosition); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<size_t> SeekableStream::size() |  | ||||||
| { |  | ||||||
|     auto original_position = TRY(tell()); |  | ||||||
| 
 |  | ||||||
|     auto seek_result = seek(0, SeekMode::FromEndPosition); |  | ||||||
|     if (seek_result.is_error()) { |  | ||||||
|         // Let's try to restore the original position, just in case.
 |  | ||||||
|         auto restore_result = seek(original_position, SeekMode::SetPosition); |  | ||||||
|         if (restore_result.is_error()) { |  | ||||||
|             dbgln("Core::SeekableStream::size: Couldn't restore initial position, stream might have incorrect position now!"); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return seek_result.release_error(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     TRY(seek(original_position, SeekMode::SetPosition)); |  | ||||||
|     return seek_result.value(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<void> SeekableStream::discard(size_t discarded_bytes) |  | ||||||
| { |  | ||||||
|     TRY(seek(discarded_bytes, SeekMode::FromCurrentPosition)); |  | ||||||
|     return {}; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<NonnullOwnPtr<File>> File::open(StringView filename, OpenMode mode, mode_t permissions) | ErrorOr<NonnullOwnPtr<File>> File::open(StringView filename, OpenMode mode, mode_t permissions) | ||||||
| { | { | ||||||
|     auto file = TRY(adopt_nonnull_own_or_enomem(new (nothrow) File(mode))); |     auto file = TRY(adopt_nonnull_own_or_enomem(new (nothrow) File(mode))); | ||||||
|  | @ -780,7 +662,7 @@ void WrappedAKOutputStream::close() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| WrapInAKInputStream::WrapInAKInputStream(Core::Stream::Stream& stream) | WrapInAKInputStream::WrapInAKInputStream(AK::Stream& stream) | ||||||
|     : m_stream(stream) |     : m_stream(stream) | ||||||
| { | { | ||||||
| } | } | ||||||
|  | @ -826,7 +708,7 @@ bool WrapInAKInputStream::discard_or_error(size_t count) | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| WrapInAKOutputStream::WrapInAKOutputStream(Core::Stream::Stream& stream) | WrapInAKOutputStream::WrapInAKOutputStream(AK::Stream& stream) | ||||||
|     : m_stream(stream) |     : m_stream(stream) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -17,6 +17,7 @@ | ||||||
| #include <AK/Noncopyable.h> | #include <AK/Noncopyable.h> | ||||||
| #include <AK/Result.h> | #include <AK/Result.h> | ||||||
| #include <AK/Span.h> | #include <AK/Span.h> | ||||||
|  | #include <AK/Stream.h> | ||||||
| #include <AK/Time.h> | #include <AK/Time.h> | ||||||
| #include <AK/Variant.h> | #include <AK/Variant.h> | ||||||
| #include <LibCore/Notifier.h> | #include <LibCore/Notifier.h> | ||||||
|  | @ -27,119 +28,6 @@ | ||||||
| 
 | 
 | ||||||
| namespace Core::Stream { | namespace Core::Stream { | ||||||
| 
 | 
 | ||||||
| /// The base, abstract class for stream operations. This class defines the
 |  | ||||||
| /// operations one can perform on every stream in LibCore.
 |  | ||||||
| /// Operations without a sensible default that are unsupported by an implementation
 |  | ||||||
| /// of a Stream should return EBADF as an error.
 |  | ||||||
| class Stream { |  | ||||||
| public: |  | ||||||
|     /// Reads into a buffer, with the maximum size being the size of the buffer.
 |  | ||||||
|     /// The amount of bytes read can be smaller than the size of the buffer.
 |  | ||||||
|     /// Returns either the bytes that were read, or an errno in the case of
 |  | ||||||
|     /// failure.
 |  | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) = 0; |  | ||||||
|     /// Tries to fill the entire buffer through reading. Returns whether the
 |  | ||||||
|     /// buffer was filled without an error.
 |  | ||||||
|     virtual ErrorOr<void> read_entire_buffer(Bytes); |  | ||||||
|     /// Reads the stream until EOF, storing the contents into a ByteBuffer which
 |  | ||||||
|     /// is returned once EOF is encountered. The block size determines the size
 |  | ||||||
|     /// of newly allocated chunks while reading.
 |  | ||||||
|     virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096); |  | ||||||
|     /// Discards the given number of bytes from the stream. As this is usually used
 |  | ||||||
|     /// as an efficient version of `read_entire_buffer`, it returns an error
 |  | ||||||
|     /// if reading failed or if not all bytes could be discarded.
 |  | ||||||
|     /// Unless specifically overwritten, this just uses read() to read into an
 |  | ||||||
|     /// internal stack-based buffer.
 |  | ||||||
|     virtual ErrorOr<void> discard(size_t discarded_bytes); |  | ||||||
| 
 |  | ||||||
|     /// Tries to write the entire contents of the buffer. It is possible for
 |  | ||||||
|     /// less than the full buffer to be written. Returns either the amount of
 |  | ||||||
|     /// bytes written into the stream, or an errno in the case of failure.
 |  | ||||||
|     virtual ErrorOr<size_t> write(ReadonlyBytes) = 0; |  | ||||||
|     /// Same as write, but does not return until either the entire buffer
 |  | ||||||
|     /// contents are written or an error occurs.
 |  | ||||||
|     virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes); |  | ||||||
| 
 |  | ||||||
|     template<typename T> |  | ||||||
|     requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs<ErrorOr<T>>; }) |  | ||||||
|     ErrorOr<T> read_value() |  | ||||||
|     { |  | ||||||
|         return T::read_from_stream(*this); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     template<typename T> |  | ||||||
|     requires(Traits<T>::is_trivially_serializable()) |  | ||||||
|     ErrorOr<T> read_value() |  | ||||||
|     { |  | ||||||
|         alignas(T) u8 buffer[sizeof(T)] = {}; |  | ||||||
|         TRY(read_entire_buffer({ &buffer, sizeof(buffer) })); |  | ||||||
|         return bit_cast<T>(buffer); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     template<typename T> |  | ||||||
|     requires(requires(T t, Stream& stream) { { t.write_to_stream(stream) } -> SameAs<ErrorOr<void>>; }) |  | ||||||
|     ErrorOr<void> write_value(T const& value) |  | ||||||
|     { |  | ||||||
|         return value.write_to_stream(*this); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     template<typename T> |  | ||||||
|     requires(Traits<T>::is_trivially_serializable()) |  | ||||||
|     ErrorOr<void> write_value(T const& value) |  | ||||||
|     { |  | ||||||
|         return write_entire_buffer({ &value, sizeof(value) }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /// Returns whether the stream has reached the end of file. For sockets,
 |  | ||||||
|     /// this most likely means that the protocol has disconnected (in the case
 |  | ||||||
|     /// of TCP). For seekable streams, this means the end of the file. Note that
 |  | ||||||
|     /// is_eof will only return true _after_ a read with 0 length, so this
 |  | ||||||
|     /// method should be called after a read.
 |  | ||||||
|     virtual bool is_eof() const = 0; |  | ||||||
| 
 |  | ||||||
|     virtual bool is_open() const = 0; |  | ||||||
|     virtual void close() = 0; |  | ||||||
| 
 |  | ||||||
|     virtual ~Stream() |  | ||||||
|     { |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| protected: |  | ||||||
|     /// Provides a default implementation of read_until_eof that works for streams
 |  | ||||||
|     /// that behave like POSIX file descriptors. expected_file_size can be
 |  | ||||||
|     /// passed as a heuristic for what the Stream subclass expects the file
 |  | ||||||
|     /// content size to be in order to reduce allocations (does not affect
 |  | ||||||
|     /// actual reading).
 |  | ||||||
|     ErrorOr<ByteBuffer> read_until_eof_impl(size_t block_size, size_t expected_file_size = 0); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| enum class SeekMode { |  | ||||||
|     SetPosition, |  | ||||||
|     FromCurrentPosition, |  | ||||||
|     FromEndPosition, |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| /// Adds seekability to Core::Stream. Classes inheriting from SeekableStream
 |  | ||||||
| /// will be seekable to any point in the stream.
 |  | ||||||
| class SeekableStream : public Stream { |  | ||||||
| public: |  | ||||||
|     /// Seeks to the given position in the given mode. Returns either the
 |  | ||||||
|     /// current position of the file, or an errno in the case of an error.
 |  | ||||||
|     virtual ErrorOr<size_t> seek(i64 offset, SeekMode) = 0; |  | ||||||
|     /// Returns the current position of the file, or an errno in the case of
 |  | ||||||
|     /// an error.
 |  | ||||||
|     virtual ErrorOr<size_t> tell() const; |  | ||||||
|     /// Returns the total size of the stream, or an errno in the case of an
 |  | ||||||
|     /// error. May not preserve the original position on the stream on failure.
 |  | ||||||
|     virtual ErrorOr<size_t> size(); |  | ||||||
|     /// Shrinks or extends the stream to the given size. Returns an errno in
 |  | ||||||
|     /// the case of an error.
 |  | ||||||
|     virtual ErrorOr<void> truncate(off_t length) = 0; |  | ||||||
|     /// Seeks until after the given amount of bytes to be discarded instead of
 |  | ||||||
|     /// reading and discarding everything manually;
 |  | ||||||
|     virtual ErrorOr<void> discard(size_t discarded_bytes) override; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| enum class PreventSIGPIPE { | enum class PreventSIGPIPE { | ||||||
|     No, |     No, | ||||||
|     Yes, |     Yes, | ||||||
|  | @ -147,7 +35,7 @@ enum class PreventSIGPIPE { | ||||||
| 
 | 
 | ||||||
| /// The Socket class is the base class for all concrete BSD-style socket
 | /// The Socket class is the base class for all concrete BSD-style socket
 | ||||||
| /// classes. Sockets are non-seekable streams which can be read byte-wise.
 | /// classes. Sockets are non-seekable streams which can be read byte-wise.
 | ||||||
| class Socket : public Stream { | class Socket : public AK::Stream { | ||||||
| public: | public: | ||||||
|     Socket(Socket&&) = default; |     Socket(Socket&&) = default; | ||||||
|     Socket& operator=(Socket&&) = default; |     Socket& operator=(Socket&&) = default; | ||||||
|  | @ -577,7 +465,7 @@ private: | ||||||
| // Buffered stream wrappers
 | // Buffered stream wrappers
 | ||||||
| 
 | 
 | ||||||
| template<typename T> | template<typename T> | ||||||
| concept StreamLike = IsBaseOf<Stream, T>; | concept StreamLike = IsBaseOf<AK::Stream, T>; | ||||||
| template<typename T> | template<typename T> | ||||||
| concept SeekableStreamLike = IsBaseOf<SeekableStream, T>; | concept SeekableStreamLike = IsBaseOf<SeekableStream, T>; | ||||||
| template<typename T> | template<typename T> | ||||||
|  | @ -1028,7 +916,7 @@ using ReusableTCPSocket = BasicReusableSocket<TCPSocket>; | ||||||
| using ReusableUDPSocket = BasicReusableSocket<UDPSocket>; | using ReusableUDPSocket = BasicReusableSocket<UDPSocket>; | ||||||
| 
 | 
 | ||||||
| // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | ||||||
| class WrappedAKInputStream final : public Stream { | class WrappedAKInputStream final : public AK::Stream { | ||||||
| public: | public: | ||||||
|     WrappedAKInputStream(NonnullOwnPtr<DeprecatedInputStream> stream); |     WrappedAKInputStream(NonnullOwnPtr<DeprecatedInputStream> stream); | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|  | @ -1043,7 +931,7 @@ private: | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | ||||||
| class WrappedAKOutputStream final : public Stream { | class WrappedAKOutputStream final : public AK::Stream { | ||||||
| public: | public: | ||||||
|     WrappedAKOutputStream(NonnullOwnPtr<DeprecatedOutputStream> stream); |     WrappedAKOutputStream(NonnullOwnPtr<DeprecatedOutputStream> stream); | ||||||
|     virtual ErrorOr<Bytes> read(Bytes) override; |     virtual ErrorOr<Bytes> read(Bytes) override; | ||||||
|  | @ -1059,25 +947,25 @@ private: | ||||||
| // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | ||||||
| class WrapInAKInputStream final : public DeprecatedInputStream { | class WrapInAKInputStream final : public DeprecatedInputStream { | ||||||
| public: | public: | ||||||
|     WrapInAKInputStream(Core::Stream::Stream& stream); |     WrapInAKInputStream(AK::Stream& stream); | ||||||
|     virtual size_t read(Bytes) override; |     virtual size_t read(Bytes) override; | ||||||
|     virtual bool unreliable_eof() const override; |     virtual bool unreliable_eof() const override; | ||||||
|     virtual bool read_or_error(Bytes) override; |     virtual bool read_or_error(Bytes) override; | ||||||
|     virtual bool discard_or_error(size_t count) override; |     virtual bool discard_or_error(size_t count) override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Core::Stream::Stream& m_stream; |     AK::Stream& m_stream; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | // Note: This is only a temporary hack, to break up the task of moving away from AK::Stream into smaller parts.
 | ||||||
| class WrapInAKOutputStream final : public DeprecatedOutputStream { | class WrapInAKOutputStream final : public DeprecatedOutputStream { | ||||||
| public: | public: | ||||||
|     WrapInAKOutputStream(Core::Stream::Stream& stream); |     WrapInAKOutputStream(AK::Stream& stream); | ||||||
|     virtual size_t write(ReadonlyBytes) override; |     virtual size_t write(ReadonlyBytes) override; | ||||||
|     virtual bool write_or_error(ReadonlyBytes) override; |     virtual bool write_or_error(ReadonlyBytes) override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Core::Stream::Stream& m_stream; |     AK::Stream& m_stream; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -75,7 +75,7 @@ void Name::randomize_case() | ||||||
|     m_name = builder.to_deprecated_string(); |     m_name = builder.to_deprecated_string(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> Name::write_to_stream(Core::Stream::Stream& stream) const | ErrorOr<void> Name::write_to_stream(AK::Stream& stream) const | ||||||
| { | { | ||||||
|     auto parts = as_string().split_view('.'); |     auto parts = as_string().split_view('.'); | ||||||
|     for (auto& part : parts) { |     for (auto& part : parts) { | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     size_t serialized_size() const; |     size_t serialized_size() const; | ||||||
|     DeprecatedString const& as_string() const { return m_name; } |     DeprecatedString const& as_string() const { return m_name; } | ||||||
|     ErrorOr<void> write_to_stream(Core::Stream::Stream&) const; |     ErrorOr<void> write_to_stream(AK::Stream&) const; | ||||||
| 
 | 
 | ||||||
|     void randomize_case(); |     void randomize_case(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace Debug::Dwarf { | namespace Debug::Dwarf { | ||||||
| 
 | 
 | ||||||
| AddressRangesV5::AddressRangesV5(NonnullOwnPtr<Core::Stream::Stream> range_lists_stream, CompilationUnit const& compilation_unit) | AddressRangesV5::AddressRangesV5(NonnullOwnPtr<AK::Stream> range_lists_stream, CompilationUnit const& compilation_unit) | ||||||
|     : m_range_lists_stream(move(range_lists_stream)) |     : m_range_lists_stream(move(range_lists_stream)) | ||||||
|     , m_compilation_unit(compilation_unit) |     , m_compilation_unit(compilation_unit) | ||||||
| { | { | ||||||
|  | @ -85,7 +85,7 @@ ErrorOr<void> AddressRangesV5::for_each_range(Function<void(Range)> callback) | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AddressRangesV4::AddressRangesV4(NonnullOwnPtr<Core::Stream::Stream> ranges_stream, CompilationUnit const& compilation_unit) | AddressRangesV4::AddressRangesV4(NonnullOwnPtr<AK::Stream> ranges_stream, CompilationUnit const& compilation_unit) | ||||||
|     : m_ranges_stream(move(ranges_stream)) |     : m_ranges_stream(move(ranges_stream)) | ||||||
|     , m_compilation_unit(compilation_unit) |     , m_compilation_unit(compilation_unit) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -24,12 +24,12 @@ class AddressRangesV5 { | ||||||
|     AK_MAKE_NONMOVABLE(AddressRangesV5); |     AK_MAKE_NONMOVABLE(AddressRangesV5); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|     AddressRangesV5(NonnullOwnPtr<Core::Stream::Stream> range_lists_stream, CompilationUnit const& compilation_unit); |     AddressRangesV5(NonnullOwnPtr<AK::Stream> range_lists_stream, CompilationUnit const& compilation_unit); | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> for_each_range(Function<void(Range)>); |     ErrorOr<void> for_each_range(Function<void(Range)>); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     NonnullOwnPtr<Core::Stream::Stream> m_range_lists_stream; |     NonnullOwnPtr<AK::Stream> m_range_lists_stream; | ||||||
|     CompilationUnit const& m_compilation_unit; |     CompilationUnit const& m_compilation_unit; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -38,12 +38,12 @@ class AddressRangesV4 { | ||||||
|     AK_MAKE_NONMOVABLE(AddressRangesV4); |     AK_MAKE_NONMOVABLE(AddressRangesV4); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|     AddressRangesV4(NonnullOwnPtr<Core::Stream::Stream> ranges_stream, CompilationUnit const&); |     AddressRangesV4(NonnullOwnPtr<AK::Stream> ranges_stream, CompilationUnit const&); | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> for_each_range(Function<void(Range)>); |     ErrorOr<void> for_each_range(Function<void(Range)>); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     NonnullOwnPtr<Core::Stream::Stream> m_ranges_stream; |     NonnullOwnPtr<AK::Stream> m_ranges_stream; | ||||||
|     CompilationUnit const& m_compilation_unit; |     CompilationUnit const& m_compilation_unit; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -80,7 +80,7 @@ ErrorOr<void> DwarfInfo::populate_compilation_units() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<AttributeValue> DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t implicit_const_value, | ErrorOr<AttributeValue> DwarfInfo::get_attribute_value(AttributeDataForm form, ssize_t implicit_const_value, | ||||||
|     Core::Stream::SeekableStream& debug_info_stream, CompilationUnit const* unit) const |     SeekableStream& debug_info_stream, CompilationUnit const* unit) const | ||||||
| { | { | ||||||
|     AttributeValue value; |     AttributeValue value; | ||||||
|     value.m_form = form; |     value.m_form = form; | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ public: | ||||||
|     ErrorOr<void> for_each_compilation_unit(Callback) const; |     ErrorOr<void> for_each_compilation_unit(Callback) const; | ||||||
| 
 | 
 | ||||||
|     ErrorOr<AttributeValue> get_attribute_value(AttributeDataForm form, ssize_t implicit_const_value, |     ErrorOr<AttributeValue> get_attribute_value(AttributeDataForm form, ssize_t implicit_const_value, | ||||||
|         Core::Stream::SeekableStream& debug_info_stream, CompilationUnit const* unit = nullptr) const; |         SeekableStream& debug_info_stream, CompilationUnit const* unit = nullptr) const; | ||||||
| 
 | 
 | ||||||
|     ErrorOr<Optional<DIE>> get_die_at_address(FlatPtr) const; |     ErrorOr<Optional<DIE>> get_die_at_address(FlatPtr) const; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -54,7 +54,7 @@ struct [[gnu::packed]] CompilationUnitHeader { | ||||||
|     u32 abbrev_offset() const { return (common.version <= 4) ? v4.abbrev_offset : v5.abbrev_offset; } |     u32 abbrev_offset() const { return (common.version <= 4) ? v4.abbrev_offset : v5.abbrev_offset; } | ||||||
|     u8 address_size() const { return (common.version <= 4) ? v4.address_size : v5.address_size; } |     u8 address_size() const { return (common.version <= 4) ? v4.address_size : v5.address_size; } | ||||||
| 
 | 
 | ||||||
|     static ErrorOr<CompilationUnitHeader> read_from_stream(Core::Stream::Stream& stream) |     static ErrorOr<CompilationUnitHeader> read_from_stream(AK::Stream& stream) | ||||||
|     { |     { | ||||||
|         CompilationUnitHeader header; |         CompilationUnitHeader header; | ||||||
|         TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) })); |         TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) })); | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace Debug::Dwarf { | namespace Debug::Dwarf { | ||||||
| 
 | 
 | ||||||
| LineProgram::LineProgram(DwarfInfo& dwarf_info, Core::Stream::SeekableStream& stream) | LineProgram::LineProgram(DwarfInfo& dwarf_info, SeekableStream& stream) | ||||||
|     : m_dwarf_info(dwarf_info) |     : m_dwarf_info(dwarf_info) | ||||||
|     , m_stream(stream) |     , m_stream(stream) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -66,7 +66,7 @@ struct [[gnu::packed]] LineProgramUnitHeader32 { | ||||||
|     u8 line_range() const { return (common.version <= 4) ? v4.line_range : v5.line_range; } |     u8 line_range() const { return (common.version <= 4) ? v4.line_range : v5.line_range; } | ||||||
|     u8 opcode_base() const { return (common.version <= 4) ? v4.opcode_base : v5.opcode_base; } |     u8 opcode_base() const { return (common.version <= 4) ? v4.opcode_base : v5.opcode_base; } | ||||||
| 
 | 
 | ||||||
|     static ErrorOr<LineProgramUnitHeader32> read_from_stream(Core::Stream::Stream& stream) |     static ErrorOr<LineProgramUnitHeader32> read_from_stream(AK::Stream& stream) | ||||||
|     { |     { | ||||||
|         LineProgramUnitHeader32 header; |         LineProgramUnitHeader32 header; | ||||||
|         TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) })); |         TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) })); | ||||||
|  | @ -109,7 +109,7 @@ class LineProgram { | ||||||
|     AK_MAKE_NONMOVABLE(LineProgram); |     AK_MAKE_NONMOVABLE(LineProgram); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|     explicit LineProgram(DwarfInfo& dwarf_info, Core::Stream::SeekableStream& stream); |     explicit LineProgram(DwarfInfo& dwarf_info, SeekableStream& stream); | ||||||
| 
 | 
 | ||||||
|     struct LineInfo { |     struct LineInfo { | ||||||
|         FlatPtr address { 0 }; |         FlatPtr address { 0 }; | ||||||
|  | @ -174,7 +174,7 @@ private: | ||||||
|     static constexpr u16 MAX_DWARF_VERSION = 5; |     static constexpr u16 MAX_DWARF_VERSION = 5; | ||||||
| 
 | 
 | ||||||
|     DwarfInfo& m_dwarf_info; |     DwarfInfo& m_dwarf_info; | ||||||
|     Core::Stream::SeekableStream& m_stream; |     SeekableStream& m_stream; | ||||||
| 
 | 
 | ||||||
|     size_t m_unit_offset { 0 }; |     size_t m_unit_offset { 0 }; | ||||||
|     LineProgramUnitHeader32 m_unit_header {}; |     LineProgramUnitHeader32 m_unit_header {}; | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace Gemini { | namespace Gemini { | ||||||
| 
 | 
 | ||||||
| Job::Job(GeminiRequest const& request, Core::Stream::Stream& output_stream) | Job::Job(GeminiRequest const& request, AK::Stream& output_stream) | ||||||
|     : Core::NetworkJob(output_stream) |     : Core::NetworkJob(output_stream) | ||||||
|     , m_request(request) |     , m_request(request) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ class Job : public Core::NetworkJob { | ||||||
|     C_OBJECT(Job); |     C_OBJECT(Job); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|     explicit Job(GeminiRequest const&, Core::Stream::Stream&); |     explicit Job(GeminiRequest const&, AK::Stream&); | ||||||
|     virtual ~Job() override = default; |     virtual ~Job() override = default; | ||||||
| 
 | 
 | ||||||
|     virtual void start(Core::Stream::Socket&) override; |     virtual void start(Core::Stream::Socket&) override; | ||||||
|  |  | ||||||
|  | @ -89,7 +89,7 @@ enum class GIFFormat { | ||||||
|     GIF89a, |     GIF89a, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static ErrorOr<GIFFormat> decode_gif_header(Core::Stream::Stream& stream) | static ErrorOr<GIFFormat> decode_gif_header(AK::Stream& stream) | ||||||
| { | { | ||||||
|     static auto valid_header_87 = "GIF87a"sv; |     static auto valid_header_87 = "GIF87a"sv; | ||||||
|     static auto valid_header_89 = "GIF89a"sv; |     static auto valid_header_89 = "GIF89a"sv; | ||||||
|  |  | ||||||
|  | @ -459,7 +459,7 @@ static inline bool is_valid_marker(const Marker marker) | ||||||
|     return false; |     return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static inline ErrorOr<Marker> read_marker_at_cursor(Core::Stream::Stream& stream) | static inline ErrorOr<Marker> read_marker_at_cursor(AK::Stream& stream) | ||||||
| { | { | ||||||
|     u16 marker = TRY(stream.read_value<BigEndian<u16>>()); |     u16 marker = TRY(stream.read_value<BigEndian<u16>>()); | ||||||
|     if (is_valid_marker(marker)) |     if (is_valid_marker(marker)) | ||||||
|  | @ -476,7 +476,7 @@ static inline ErrorOr<Marker> read_marker_at_cursor(Core::Stream::Stream& stream | ||||||
|     return is_valid_marker(marker) ? marker : JPG_INVALID; |     return is_valid_marker(marker) ? marker : JPG_INVALID; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> read_start_of_scan(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) | static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPGLoadingContext& context) | ||||||
| { | { | ||||||
|     if (context.state < JPGLoadingContext::State::FrameDecoded) { |     if (context.state < JPGLoadingContext::State::FrameDecoded) { | ||||||
|         dbgln_if(JPG_DEBUG, "{}: SOS found before reading a SOF!", TRY(stream.tell())); |         dbgln_if(JPG_DEBUG, "{}: SOS found before reading a SOF!", TRY(stream.tell())); | ||||||
|  | @ -537,7 +537,7 @@ static ErrorOr<void> read_start_of_scan(Core::Stream::SeekableStream& stream, JP | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> read_reset_marker(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) | static ErrorOr<void> read_reset_marker(AK::SeekableStream& stream, JPGLoadingContext& context) | ||||||
| { | { | ||||||
|     u16 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2; |     u16 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2; | ||||||
|     if (bytes_to_read != 2) { |     if (bytes_to_read != 2) { | ||||||
|  | @ -548,7 +548,7 @@ static ErrorOr<void> read_reset_marker(Core::Stream::SeekableStream& stream, JPG | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> read_huffman_table(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) | static ErrorOr<void> read_huffman_table(AK::SeekableStream& stream, JPGLoadingContext& context) | ||||||
| { | { | ||||||
|     i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()); |     i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()); | ||||||
|     TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); |     TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); | ||||||
|  | @ -600,7 +600,7 @@ static ErrorOr<void> read_huffman_table(Core::Stream::SeekableStream& stream, JP | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> read_icc_profile(Core::Stream::SeekableStream& stream, JPGLoadingContext& context, int bytes_to_read) | static ErrorOr<void> read_icc_profile(SeekableStream& stream, JPGLoadingContext& context, int bytes_to_read) | ||||||
| { | { | ||||||
|     if (bytes_to_read <= 2) |     if (bytes_to_read <= 2) | ||||||
|         return Error::from_string_literal("icc marker too small"); |         return Error::from_string_literal("icc marker too small"); | ||||||
|  | @ -658,7 +658,7 @@ static ErrorOr<void> read_icc_profile(Core::Stream::SeekableStream& stream, JPGL | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> read_app_marker(Core::Stream::SeekableStream& stream, JPGLoadingContext& context, int app_marker_number) | static ErrorOr<void> read_app_marker(SeekableStream& stream, JPGLoadingContext& context, int app_marker_number) | ||||||
| { | { | ||||||
|     i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()); |     i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()); | ||||||
|     TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); |     TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); | ||||||
|  | @ -718,7 +718,7 @@ static inline void set_macroblock_metadata(JPGLoadingContext& context) | ||||||
|     context.mblock_meta.total = context.mblock_meta.hcount * context.mblock_meta.vcount; |     context.mblock_meta.total = context.mblock_meta.hcount * context.mblock_meta.vcount; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> read_start_of_frame(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) | static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingContext& context) | ||||||
| { | { | ||||||
|     if (context.state == JPGLoadingContext::FrameDecoded) { |     if (context.state == JPGLoadingContext::FrameDecoded) { | ||||||
|         dbgln_if(JPG_DEBUG, "{}: SOF repeated!", TRY(stream.tell())); |         dbgln_if(JPG_DEBUG, "{}: SOF repeated!", TRY(stream.tell())); | ||||||
|  | @ -802,7 +802,7 @@ static ErrorOr<void> read_start_of_frame(Core::Stream::SeekableStream& stream, J | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> read_quantization_table(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) | static ErrorOr<void> read_quantization_table(AK::SeekableStream& stream, JPGLoadingContext& context) | ||||||
| { | { | ||||||
|     i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2; |     i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2; | ||||||
|     TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); |     TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); | ||||||
|  | @ -838,7 +838,7 @@ static ErrorOr<void> read_quantization_table(Core::Stream::SeekableStream& strea | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> skip_marker_with_length(Core::Stream::Stream& stream) | static ErrorOr<void> skip_marker_with_length(AK::Stream& stream) | ||||||
| { | { | ||||||
|     u16 bytes_to_skip = TRY(stream.read_value<BigEndian<u16>>()) - 2; |     u16 bytes_to_skip = TRY(stream.read_value<BigEndian<u16>>()) - 2; | ||||||
|     TRY(stream.discard(bytes_to_skip)); |     TRY(stream.discard(bytes_to_skip)); | ||||||
|  | @ -1086,7 +1086,7 @@ static ErrorOr<void> compose_bitmap(JPGLoadingContext& context, Vector<Macrobloc | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> parse_header(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) | static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPGLoadingContext& context) | ||||||
| { | { | ||||||
|     auto marker = TRY(read_marker_at_cursor(stream)); |     auto marker = TRY(read_marker_at_cursor(stream)); | ||||||
|     if (marker != JPG_SOI) { |     if (marker != JPG_SOI) { | ||||||
|  | @ -1163,7 +1163,7 @@ static ErrorOr<void> parse_header(Core::Stream::SeekableStream& stream, JPGLoadi | ||||||
|     VERIFY_NOT_REACHED(); |     VERIFY_NOT_REACHED(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> scan_huffman_stream(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) | static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingContext& context) | ||||||
| { | { | ||||||
|     u8 last_byte; |     u8 last_byte; | ||||||
|     u8 current_byte = TRY(stream.read_value<u8>()); |     u8 current_byte = TRY(stream.read_value<u8>()); | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ static constexpr u8 QOI_OP_RUN = 0b11000000; | ||||||
| static constexpr u8 QOI_MASK_2 = 0b11000000; | static constexpr u8 QOI_MASK_2 = 0b11000000; | ||||||
| static constexpr u8 END_MARKER[] = { 0, 0, 0, 0, 0, 0, 0, 1 }; | static constexpr u8 END_MARKER[] = { 0, 0, 0, 0, 0, 0, 0, 1 }; | ||||||
| 
 | 
 | ||||||
| static ErrorOr<QOIHeader> decode_qoi_header(Core::Stream::Stream& stream) | static ErrorOr<QOIHeader> decode_qoi_header(AK::Stream& stream) | ||||||
| { | { | ||||||
|     auto header = TRY(stream.read_value<QOIHeader>()); |     auto header = TRY(stream.read_value<QOIHeader>()); | ||||||
|     if (StringView { header.magic, array_size(header.magic) } != QOI_MAGIC) |     if (StringView { header.magic, array_size(header.magic) } != QOI_MAGIC) | ||||||
|  | @ -31,7 +31,7 @@ static ErrorOr<QOIHeader> decode_qoi_header(Core::Stream::Stream& stream) | ||||||
|     return header; |     return header; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<Color> decode_qoi_op_rgb(Core::Stream::Stream& stream, u8 first_byte, Color pixel) | static ErrorOr<Color> decode_qoi_op_rgb(AK::Stream& stream, u8 first_byte, Color pixel) | ||||||
| { | { | ||||||
|     VERIFY(first_byte == QOI_OP_RGB); |     VERIFY(first_byte == QOI_OP_RGB); | ||||||
|     u8 bytes[3]; |     u8 bytes[3]; | ||||||
|  | @ -41,7 +41,7 @@ static ErrorOr<Color> decode_qoi_op_rgb(Core::Stream::Stream& stream, u8 first_b | ||||||
|     return Color { bytes[0], bytes[1], bytes[2], pixel.alpha() }; |     return Color { bytes[0], bytes[1], bytes[2], pixel.alpha() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<Color> decode_qoi_op_rgba(Core::Stream::Stream& stream, u8 first_byte) | static ErrorOr<Color> decode_qoi_op_rgba(AK::Stream& stream, u8 first_byte) | ||||||
| { | { | ||||||
|     VERIFY(first_byte == QOI_OP_RGBA); |     VERIFY(first_byte == QOI_OP_RGBA); | ||||||
|     u8 bytes[4]; |     u8 bytes[4]; | ||||||
|  | @ -49,7 +49,7 @@ static ErrorOr<Color> decode_qoi_op_rgba(Core::Stream::Stream& stream, u8 first_ | ||||||
|     return Color { bytes[0], bytes[1], bytes[2], bytes[3] }; |     return Color { bytes[0], bytes[1], bytes[2], bytes[3] }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<u8> decode_qoi_op_index(Core::Stream::Stream&, u8 first_byte) | static ErrorOr<u8> decode_qoi_op_index(AK::Stream&, u8 first_byte) | ||||||
| { | { | ||||||
|     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_INDEX); |     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_INDEX); | ||||||
|     u8 index = first_byte & ~QOI_MASK_2; |     u8 index = first_byte & ~QOI_MASK_2; | ||||||
|  | @ -57,7 +57,7 @@ static ErrorOr<u8> decode_qoi_op_index(Core::Stream::Stream&, u8 first_byte) | ||||||
|     return index; |     return index; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<Color> decode_qoi_op_diff(Core::Stream::Stream&, u8 first_byte, Color pixel) | static ErrorOr<Color> decode_qoi_op_diff(AK::Stream&, u8 first_byte, Color pixel) | ||||||
| { | { | ||||||
|     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_DIFF); |     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_DIFF); | ||||||
|     u8 dr = (first_byte & 0b00110000) >> 4; |     u8 dr = (first_byte & 0b00110000) >> 4; | ||||||
|  | @ -74,7 +74,7 @@ static ErrorOr<Color> decode_qoi_op_diff(Core::Stream::Stream&, u8 first_byte, C | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<Color> decode_qoi_op_luma(Core::Stream::Stream& stream, u8 first_byte, Color pixel) | static ErrorOr<Color> decode_qoi_op_luma(AK::Stream& stream, u8 first_byte, Color pixel) | ||||||
| { | { | ||||||
|     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_LUMA); |     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_LUMA); | ||||||
|     auto byte = TRY(stream.read_value<u8>()); |     auto byte = TRY(stream.read_value<u8>()); | ||||||
|  | @ -91,7 +91,7 @@ static ErrorOr<Color> decode_qoi_op_luma(Core::Stream::Stream& stream, u8 first_ | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<u8> decode_qoi_op_run(Core::Stream::Stream&, u8 first_byte) | static ErrorOr<u8> decode_qoi_op_run(AK::Stream&, u8 first_byte) | ||||||
| { | { | ||||||
|     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_RUN); |     VERIFY((first_byte & QOI_MASK_2) == QOI_OP_RUN); | ||||||
|     u8 run = first_byte & ~QOI_MASK_2; |     u8 run = first_byte & ~QOI_MASK_2; | ||||||
|  | @ -107,7 +107,7 @@ static ErrorOr<u8> decode_qoi_op_run(Core::Stream::Stream&, u8 first_byte) | ||||||
|     return run; |     return run; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> decode_qoi_end_marker(Core::Stream::Stream& stream) | static ErrorOr<void> decode_qoi_end_marker(AK::Stream& stream) | ||||||
| { | { | ||||||
|     u8 bytes[array_size(END_MARKER)]; |     u8 bytes[array_size(END_MARKER)]; | ||||||
|     TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) })); |     TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) })); | ||||||
|  | @ -118,7 +118,7 @@ static ErrorOr<void> decode_qoi_end_marker(Core::Stream::Stream& stream) | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(Core::Stream::Stream& stream, u32 width, u32 height) | static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(AK::Stream& stream, u32 width, u32 height) | ||||||
| { | { | ||||||
|     // FIXME: Why is Gfx::Bitmap's size signed? Makes no sense whatsoever.
 |     // FIXME: Why is Gfx::Bitmap's size signed? Makes no sense whatsoever.
 | ||||||
|     if (width > NumericLimits<int>::max()) |     if (width > NumericLimits<int>::max()) | ||||||
|  | @ -162,7 +162,7 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(Core::Stream::Stream& str | ||||||
|     return { move(bitmap) }; |     return { move(bitmap) }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QOIImageDecoderPlugin::QOIImageDecoderPlugin(NonnullOwnPtr<Core::Stream::Stream> stream) | QOIImageDecoderPlugin::QOIImageDecoderPlugin(NonnullOwnPtr<AK::Stream> stream) | ||||||
| { | { | ||||||
|     m_context = make<QOILoadingContext>(); |     m_context = make<QOILoadingContext>(); | ||||||
|     m_context->stream = move(stream); |     m_context->stream = move(stream); | ||||||
|  | @ -234,7 +234,7 @@ ErrorOr<ImageFrameDescriptor> QOIImageDecoderPlugin::frame(size_t index) | ||||||
|     return *m_context->error; |     return *m_context->error; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(Core::Stream::Stream& stream) | ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(AK::Stream& stream) | ||||||
| { | { | ||||||
|     VERIFY(m_context->state < QOILoadingContext::State::HeaderDecoded); |     VERIFY(m_context->state < QOILoadingContext::State::HeaderDecoded); | ||||||
|     auto error_or_header = decode_qoi_header(stream); |     auto error_or_header = decode_qoi_header(stream); | ||||||
|  | @ -248,7 +248,7 @@ ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(Core::Stre | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> QOIImageDecoderPlugin::decode_image_and_update_context(Core::Stream::Stream& stream) | ErrorOr<void> QOIImageDecoderPlugin::decode_image_and_update_context(AK::Stream& stream) | ||||||
| { | { | ||||||
|     VERIFY(m_context->state < QOILoadingContext::State::ImageDecoded); |     VERIFY(m_context->state < QOILoadingContext::State::ImageDecoded); | ||||||
|     auto error_or_bitmap = decode_qoi_image(stream, m_context->header.width, m_context->header.height); |     auto error_or_bitmap = decode_qoi_image(stream, m_context->header.width, m_context->header.height); | ||||||
|  |  | ||||||
|  | @ -32,7 +32,7 @@ struct QOILoadingContext { | ||||||
|         Error, |         Error, | ||||||
|     }; |     }; | ||||||
|     State state { State::NotDecoded }; |     State state { State::NotDecoded }; | ||||||
|     OwnPtr<Core::Stream::Stream> stream {}; |     OwnPtr<AK::Stream> stream {}; | ||||||
|     QOIHeader header {}; |     QOIHeader header {}; | ||||||
|     RefPtr<Bitmap> bitmap; |     RefPtr<Bitmap> bitmap; | ||||||
|     Optional<Error> error; |     Optional<Error> error; | ||||||
|  | @ -56,10 +56,10 @@ public: | ||||||
|     virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override; |     virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     ErrorOr<void> decode_header_and_update_context(Core::Stream::Stream&); |     ErrorOr<void> decode_header_and_update_context(AK::Stream&); | ||||||
|     ErrorOr<void> decode_image_and_update_context(Core::Stream::Stream&); |     ErrorOr<void> decode_image_and_update_context(AK::Stream&); | ||||||
| 
 | 
 | ||||||
|     QOIImageDecoderPlugin(NonnullOwnPtr<Core::Stream::Stream>); |     QOIImageDecoderPlugin(NonnullOwnPtr<AK::Stream>); | ||||||
| 
 | 
 | ||||||
|     OwnPtr<QOILoadingContext> m_context; |     OwnPtr<QOILoadingContext> m_context; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -31,7 +31,7 @@ public: | ||||||
|     Function<Vector<TLS::Certificate>()> on_certificate_requested; |     Function<Vector<TLS::Certificate>()> on_certificate_requested; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     explicit HttpsJob(HttpRequest&& request, Core::Stream::Stream& output_stream) |     explicit HttpsJob(HttpRequest&& request, AK::Stream& output_stream) | ||||||
|         : Job(move(request), output_stream) |         : Job(move(request), output_stream) | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -86,7 +86,7 @@ static ErrorOr<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Deprec | ||||||
|     return buf; |     return buf; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Job::Job(HttpRequest&& request, Core::Stream::Stream& output_stream) | Job::Job(HttpRequest&& request, AK::Stream& output_stream) | ||||||
|     : Core::NetworkJob(output_stream) |     : Core::NetworkJob(output_stream) | ||||||
|     , m_request(move(request)) |     , m_request(move(request)) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ class Job : public Core::NetworkJob { | ||||||
|     C_OBJECT(Job); |     C_OBJECT(Job); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|     explicit Job(HttpRequest&&, Core::Stream::Stream&); |     explicit Job(HttpRequest&&, AK::Stream&); | ||||||
|     virtual ~Job() override = default; |     virtual ~Job() override = default; | ||||||
| 
 | 
 | ||||||
|     virtual void start(Core::Stream::Socket&) override; |     virtual void start(Core::Stream::Socket&) override; | ||||||
|  |  | ||||||
|  | @ -32,7 +32,7 @@ inline ErrorOr<T> decode(Decoder&) | ||||||
| 
 | 
 | ||||||
| class Decoder { | class Decoder { | ||||||
| public: | public: | ||||||
|     Decoder(Core::Stream::Stream& stream, Core::Stream::LocalSocket& socket) |     Decoder(AK::Stream& stream, Core::Stream::LocalSocket& socket) | ||||||
|         : m_stream(stream) |         : m_stream(stream) | ||||||
|         , m_socket(socket) |         , m_socket(socket) | ||||||
|     { |     { | ||||||
|  | @ -59,7 +59,7 @@ public: | ||||||
|     Core::Stream::LocalSocket& socket() { return m_socket; } |     Core::Stream::LocalSocket& socket() { return m_socket; } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Core::Stream::Stream& m_stream; |     AK::Stream& m_stream; | ||||||
|     Core::Stream::LocalSocket& m_socket; |     Core::Stream::LocalSocket& m_socket; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ | ||||||
| namespace JS { | namespace JS { | ||||||
| struct PrintContext { | struct PrintContext { | ||||||
|     JS::VM& vm; |     JS::VM& vm; | ||||||
|     Core::Stream::Stream& stream; |     AK::Stream& stream; | ||||||
|     bool strip_ansi { false }; |     bool strip_ansi { false }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1574,7 +1574,7 @@ void Editor::strip_styles(bool strip_anchored) | ||||||
|     m_refresh_needed = true; |     m_refresh_needed = true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> Editor::reposition_cursor(Core::Stream::Stream& stream, bool to_end) | ErrorOr<void> Editor::reposition_cursor(AK::Stream& stream, bool to_end) | ||||||
| { | { | ||||||
|     auto cursor = m_cursor; |     auto cursor = m_cursor; | ||||||
|     auto saved_cursor = m_cursor; |     auto saved_cursor = m_cursor; | ||||||
|  | @ -1596,12 +1596,12 @@ ErrorOr<void> Editor::reposition_cursor(Core::Stream::Stream& stream, bool to_en | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> VT::move_absolute(u32 row, u32 col, Core::Stream::Stream& stream) | ErrorOr<void> VT::move_absolute(u32 row, u32 col, AK::Stream& stream) | ||||||
| { | { | ||||||
|     return stream.write_entire_buffer(DeprecatedString::formatted("\033[{};{}H", row, col).bytes()); |     return stream.write_entire_buffer(DeprecatedString::formatted("\033[{};{}H", row, col).bytes()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> VT::move_relative(int row, int col, Core::Stream::Stream& stream) | ErrorOr<void> VT::move_relative(int row, int col, AK::Stream& stream) | ||||||
| { | { | ||||||
|     char x_op = 'A', y_op = 'D'; |     char x_op = 'A', y_op = 'D'; | ||||||
| 
 | 
 | ||||||
|  | @ -1753,7 +1753,7 @@ DeprecatedString Style::to_deprecated_string() const | ||||||
|     return builder.to_deprecated_string(); |     return builder.to_deprecated_string(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> VT::apply_style(Style const& style, Core::Stream::Stream& stream, bool is_starting) | ErrorOr<void> VT::apply_style(Style const& style, AK::Stream& stream, bool is_starting) | ||||||
| { | { | ||||||
|     if (is_starting) { |     if (is_starting) { | ||||||
|         TRY(stream.write_entire_buffer(DeprecatedString::formatted("\033[{};{};{}m{}{}{}", |         TRY(stream.write_entire_buffer(DeprecatedString::formatted("\033[{};{};{}m{}{}{}", | ||||||
|  | @ -1771,7 +1771,7 @@ ErrorOr<void> VT::apply_style(Style const& style, Core::Stream::Stream& stream, | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> VT::clear_lines(size_t count_above, size_t count_below, Core::Stream::Stream& stream) | ErrorOr<void> VT::clear_lines(size_t count_above, size_t count_below, AK::Stream& stream) | ||||||
| { | { | ||||||
|     if (count_below + count_above == 0) { |     if (count_below + count_above == 0) { | ||||||
|         TRY(stream.write_entire_buffer("\033[2K"sv.bytes())); |         TRY(stream.write_entire_buffer("\033[2K"sv.bytes())); | ||||||
|  | @ -1790,17 +1790,17 @@ ErrorOr<void> VT::clear_lines(size_t count_above, size_t count_below, Core::Stre | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> VT::save_cursor(Core::Stream::Stream& stream) | ErrorOr<void> VT::save_cursor(AK::Stream& stream) | ||||||
| { | { | ||||||
|     return stream.write_entire_buffer("\033[s"sv.bytes()); |     return stream.write_entire_buffer("\033[s"sv.bytes()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> VT::restore_cursor(Core::Stream::Stream& stream) | ErrorOr<void> VT::restore_cursor(AK::Stream& stream) | ||||||
| { | { | ||||||
|     return stream.write_entire_buffer("\033[u"sv.bytes()); |     return stream.write_entire_buffer("\033[u"sv.bytes()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> VT::clear_to_end_of_line(Core::Stream::Stream& stream) | ErrorOr<void> VT::clear_to_end_of_line(AK::Stream& stream) | ||||||
| { | { | ||||||
|     return stream.write_entire_buffer("\033[K"sv.bytes()); |     return stream.write_entire_buffer("\033[K"sv.bytes()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -393,7 +393,7 @@ private: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void recalculate_origin(); |     void recalculate_origin(); | ||||||
|     ErrorOr<void> reposition_cursor(Core::Stream::Stream&, bool to_end = false); |     ErrorOr<void> reposition_cursor(AK::Stream&, bool to_end = false); | ||||||
| 
 | 
 | ||||||
|     struct CodepointRange { |     struct CodepointRange { | ||||||
|         size_t start { 0 }; |         size_t start { 0 }; | ||||||
|  |  | ||||||
|  | @ -13,13 +13,13 @@ | ||||||
| namespace Line { | namespace Line { | ||||||
| namespace VT { | namespace VT { | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> save_cursor(Core::Stream::Stream&); | ErrorOr<void> save_cursor(AK::Stream&); | ||||||
| ErrorOr<void> restore_cursor(Core::Stream::Stream&); | ErrorOr<void> restore_cursor(AK::Stream&); | ||||||
| ErrorOr<void> clear_to_end_of_line(Core::Stream::Stream&); | ErrorOr<void> clear_to_end_of_line(AK::Stream&); | ||||||
| ErrorOr<void> clear_lines(size_t count_above, size_t count_below, Core::Stream::Stream&); | ErrorOr<void> clear_lines(size_t count_above, size_t count_below, AK::Stream&); | ||||||
| ErrorOr<void> move_relative(int x, int y, Core::Stream::Stream&); | ErrorOr<void> move_relative(int x, int y, AK::Stream&); | ||||||
| ErrorOr<void> move_absolute(u32 x, u32 y, Core::Stream::Stream&); | ErrorOr<void> move_absolute(u32 x, u32 y, AK::Stream&); | ||||||
| ErrorOr<void> apply_style(Style const&, Core::Stream::Stream&, bool is_starting = true); | ErrorOr<void> apply_style(Style const&, AK::Stream&, bool is_starting = true); | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ bool Request::stop() | ||||||
|     return m_client->stop_request({}, *this); |     return m_client->stop_request({}, *this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Request::stream_into(Core::Stream::Stream& stream) | void Request::stream_into(AK::Stream& stream) | ||||||
| { | { | ||||||
|     VERIFY(!m_internal_stream_data); |     VERIFY(!m_internal_stream_data); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ public: | ||||||
|     int fd() const { return m_fd; } |     int fd() const { return m_fd; } | ||||||
|     bool stop(); |     bool stop(); | ||||||
| 
 | 
 | ||||||
|     void stream_into(Core::Stream::Stream&); |     void stream_into(AK::Stream&); | ||||||
| 
 | 
 | ||||||
|     bool should_buffer_all_input() const { return m_should_buffer_all_input; } |     bool should_buffer_all_input() const { return m_should_buffer_all_input; } | ||||||
|     /// Note: Will override `on_finish', and `on_headers_received', and expects `on_buffered_request_finish' to be set!
 |     /// Note: Will override `on_finish', and `on_headers_received', and expects `on_buffered_request_finish' to be set!
 | ||||||
|  | @ -74,12 +74,12 @@ private: | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     struct InternalStreamData { |     struct InternalStreamData { | ||||||
|         InternalStreamData(NonnullOwnPtr<Core::Stream::Stream> stream) |         InternalStreamData(NonnullOwnPtr<AK::Stream> stream) | ||||||
|             : read_stream(move(stream)) |             : read_stream(move(stream)) | ||||||
|         { |         { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         NonnullOwnPtr<Core::Stream::Stream> read_stream; |         NonnullOwnPtr<AK::Stream> read_stream; | ||||||
|         RefPtr<Core::Notifier> read_notifier; |         RefPtr<Core::Notifier> read_notifier; | ||||||
|         bool success; |         bool success; | ||||||
|         u32 total_size { 0 }; |         u32 total_size { 0 }; | ||||||
|  |  | ||||||
|  | @ -142,9 +142,9 @@ ErrorOr<void> Heap::seek_block(u32 block) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (block == m_end_of_file) |     if (block == m_end_of_file) | ||||||
|         TRY(m_file->seek(0, Core::Stream::SeekMode::FromEndPosition)); |         TRY(m_file->seek(0, SeekMode::FromEndPosition)); | ||||||
|     else |     else | ||||||
|         TRY(m_file->seek(block * BLOCKSIZE, Core::Stream::SeekMode::SetPosition)); |         TRY(m_file->seek(block * BLOCKSIZE, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace Wasm { | namespace Wasm { | ||||||
| 
 | 
 | ||||||
| ParseError with_eof_check(Core::Stream::Stream const& stream, ParseError error_if_not_eof) | ParseError with_eof_check(AK::Stream const& stream, ParseError error_if_not_eof) | ||||||
| { | { | ||||||
|     if (stream.is_eof()) |     if (stream.is_eof()) | ||||||
|         return ParseError::UnexpectedEof; |         return ParseError::UnexpectedEof; | ||||||
|  | @ -21,7 +21,7 @@ ParseError with_eof_check(Core::Stream::Stream const& stream, ParseError error_i | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template<typename T> | template<typename T> | ||||||
| static auto parse_vector(Core::Stream::Stream& stream) | static auto parse_vector(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger; |     ScopeLogger<WASM_BINPARSER_DEBUG> logger; | ||||||
|     if constexpr (requires { T::parse(stream); }) { |     if constexpr (requires { T::parse(stream); }) { | ||||||
|  | @ -72,7 +72,7 @@ static auto parse_vector(Core::Stream::Stream& stream) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ParseResult<DeprecatedString> parse_name(Core::Stream::Stream& stream) | static ParseResult<DeprecatedString> parse_name(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger; |     ScopeLogger<WASM_BINPARSER_DEBUG> logger; | ||||||
|     auto data = parse_vector<u8>(stream); |     auto data = parse_vector<u8>(stream); | ||||||
|  | @ -88,8 +88,8 @@ struct ParseUntilAnyOfResult { | ||||||
|     Vector<T> values; |     Vector<T> values; | ||||||
| }; | }; | ||||||
| template<typename T, u8... terminators, typename... Args> | template<typename T, u8... terminators, typename... Args> | ||||||
| static ParseResult<ParseUntilAnyOfResult<T>> parse_until_any_of(Core::Stream::Stream& stream, Args&... args) | static ParseResult<ParseUntilAnyOfResult<T>> parse_until_any_of(AK::Stream& stream, Args&... args) | ||||||
| requires(requires(Core::Stream::Stream& stream, Args... args) { T::parse(stream, args...); }) | requires(requires(AK::Stream& stream, Args... args) { T::parse(stream, args...); }) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger; |     ScopeLogger<WASM_BINPARSER_DEBUG> logger; | ||||||
|     ReconsumableStream new_stream { stream }; |     ReconsumableStream new_stream { stream }; | ||||||
|  | @ -118,7 +118,7 @@ requires(requires(Core::Stream::Stream& stream, Args... args) { T::parse(stream, | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ValueType> ValueType::parse(Core::Stream::Stream& stream) | ParseResult<ValueType> ValueType::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ValueType"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ValueType"sv); | ||||||
|     auto tag_or_error = stream.read_value<u8>(); |     auto tag_or_error = stream.read_value<u8>(); | ||||||
|  | @ -145,7 +145,7 @@ ParseResult<ValueType> ValueType::parse(Core::Stream::Stream& stream) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ResultType> ResultType::parse(Core::Stream::Stream& stream) | ParseResult<ResultType> ResultType::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ResultType"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ResultType"sv); | ||||||
|     auto types = parse_vector<ValueType>(stream); |     auto types = parse_vector<ValueType>(stream); | ||||||
|  | @ -154,7 +154,7 @@ ParseResult<ResultType> ResultType::parse(Core::Stream::Stream& stream) | ||||||
|     return ResultType { types.release_value() }; |     return ResultType { types.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<FunctionType> FunctionType::parse(Core::Stream::Stream& stream) | ParseResult<FunctionType> FunctionType::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionType"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionType"sv); | ||||||
|     auto tag_or_error = stream.read_value<u8>(); |     auto tag_or_error = stream.read_value<u8>(); | ||||||
|  | @ -178,7 +178,7 @@ ParseResult<FunctionType> FunctionType::parse(Core::Stream::Stream& stream) | ||||||
|     return FunctionType { parameters_result.release_value(), results_result.release_value() }; |     return FunctionType { parameters_result.release_value(), results_result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<Limits> Limits::parse(Core::Stream::Stream& stream) | ParseResult<Limits> Limits::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Limits"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Limits"sv); | ||||||
|     auto flag_or_error = stream.read_value<u8>(); |     auto flag_or_error = stream.read_value<u8>(); | ||||||
|  | @ -207,7 +207,7 @@ ParseResult<Limits> Limits::parse(Core::Stream::Stream& stream) | ||||||
|     return Limits { static_cast<u32>(min), move(max) }; |     return Limits { static_cast<u32>(min), move(max) }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<MemoryType> MemoryType::parse(Core::Stream::Stream& stream) | ParseResult<MemoryType> MemoryType::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemoryType"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemoryType"sv); | ||||||
|     auto limits_result = Limits::parse(stream); |     auto limits_result = Limits::parse(stream); | ||||||
|  | @ -216,7 +216,7 @@ ParseResult<MemoryType> MemoryType::parse(Core::Stream::Stream& stream) | ||||||
|     return MemoryType { limits_result.release_value() }; |     return MemoryType { limits_result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<TableType> TableType::parse(Core::Stream::Stream& stream) | ParseResult<TableType> TableType::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableType"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableType"sv); | ||||||
|     auto type_result = ValueType::parse(stream); |     auto type_result = ValueType::parse(stream); | ||||||
|  | @ -230,7 +230,7 @@ ParseResult<TableType> TableType::parse(Core::Stream::Stream& stream) | ||||||
|     return TableType { type_result.release_value(), limits_result.release_value() }; |     return TableType { type_result.release_value(), limits_result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<GlobalType> GlobalType::parse(Core::Stream::Stream& stream) | ParseResult<GlobalType> GlobalType::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalType"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalType"sv); | ||||||
|     auto type_result = ValueType::parse(stream); |     auto type_result = ValueType::parse(stream); | ||||||
|  | @ -249,7 +249,7 @@ ParseResult<GlobalType> GlobalType::parse(Core::Stream::Stream& stream) | ||||||
|     return GlobalType { type_result.release_value(), mutable_ == 0x01 }; |     return GlobalType { type_result.release_value(), mutable_ == 0x01 }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<BlockType> BlockType::parse(Core::Stream::Stream& stream) | ParseResult<BlockType> BlockType::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("BlockType"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("BlockType"sv); | ||||||
|     auto kind_or_error = stream.read_value<u8>(); |     auto kind_or_error = stream.read_value<u8>(); | ||||||
|  | @ -282,7 +282,7 @@ ParseResult<BlockType> BlockType::parse(Core::Stream::Stream& stream) | ||||||
|     return BlockType { TypeIndex(index_value) }; |     return BlockType { TypeIndex(index_value) }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<Vector<Instruction>> Instruction::parse(Core::Stream::Stream& stream, InstructionPointer& ip) | ParseResult<Vector<Instruction>> Instruction::parse(AK::Stream& stream, InstructionPointer& ip) | ||||||
| { | { | ||||||
|     struct NestedInstructionState { |     struct NestedInstructionState { | ||||||
|         Vector<Instruction> prior_instructions; |         Vector<Instruction> prior_instructions; | ||||||
|  | @ -782,7 +782,7 @@ ParseResult<Vector<Instruction>> Instruction::parse(Core::Stream::Stream& stream | ||||||
|     return resulting_instructions; |     return resulting_instructions; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<CustomSection> CustomSection::parse(Core::Stream::Stream& stream) | ParseResult<CustomSection> CustomSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("CustomSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("CustomSection"sv); | ||||||
|     auto name = parse_name(stream); |     auto name = parse_name(stream); | ||||||
|  | @ -808,7 +808,7 @@ ParseResult<CustomSection> CustomSection::parse(Core::Stream::Stream& stream) | ||||||
|     return CustomSection(name.release_value(), move(data_buffer)); |     return CustomSection(name.release_value(), move(data_buffer)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<TypeSection> TypeSection::parse(Core::Stream::Stream& stream) | ParseResult<TypeSection> TypeSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("TypeSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("TypeSection"sv); | ||||||
|     auto types = parse_vector<FunctionType>(stream); |     auto types = parse_vector<FunctionType>(stream); | ||||||
|  | @ -817,7 +817,7 @@ ParseResult<TypeSection> TypeSection::parse(Core::Stream::Stream& stream) | ||||||
|     return TypeSection { types.release_value() }; |     return TypeSection { types.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ImportSection::Import> ImportSection::Import::parse(Core::Stream::Stream& stream) | ParseResult<ImportSection::Import> ImportSection::Import::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Import"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Import"sv); | ||||||
|     auto module = parse_name(stream); |     auto module = parse_name(stream); | ||||||
|  | @ -850,7 +850,7 @@ ParseResult<ImportSection::Import> ImportSection::Import::parse(Core::Stream::St | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ImportSection> ImportSection::parse(Core::Stream::Stream& stream) | ParseResult<ImportSection> ImportSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ImportSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ImportSection"sv); | ||||||
|     auto imports = parse_vector<Import>(stream); |     auto imports = parse_vector<Import>(stream); | ||||||
|  | @ -859,7 +859,7 @@ ParseResult<ImportSection> ImportSection::parse(Core::Stream::Stream& stream) | ||||||
|     return ImportSection { imports.release_value() }; |     return ImportSection { imports.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<FunctionSection> FunctionSection::parse(Core::Stream::Stream& stream) | ParseResult<FunctionSection> FunctionSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionSection"sv); | ||||||
|     auto indices = parse_vector<size_t>(stream); |     auto indices = parse_vector<size_t>(stream); | ||||||
|  | @ -874,7 +874,7 @@ ParseResult<FunctionSection> FunctionSection::parse(Core::Stream::Stream& stream | ||||||
|     return FunctionSection { move(typed_indices) }; |     return FunctionSection { move(typed_indices) }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<TableSection::Table> TableSection::Table::parse(Core::Stream::Stream& stream) | ParseResult<TableSection::Table> TableSection::Table::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Table"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Table"sv); | ||||||
|     auto type = TableType::parse(stream); |     auto type = TableType::parse(stream); | ||||||
|  | @ -883,7 +883,7 @@ ParseResult<TableSection::Table> TableSection::Table::parse(Core::Stream::Stream | ||||||
|     return Table { type.release_value() }; |     return Table { type.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<TableSection> TableSection::parse(Core::Stream::Stream& stream) | ParseResult<TableSection> TableSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableSection"sv); | ||||||
|     auto tables = parse_vector<Table>(stream); |     auto tables = parse_vector<Table>(stream); | ||||||
|  | @ -892,7 +892,7 @@ ParseResult<TableSection> TableSection::parse(Core::Stream::Stream& stream) | ||||||
|     return TableSection { tables.release_value() }; |     return TableSection { tables.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<MemorySection::Memory> MemorySection::Memory::parse(Core::Stream::Stream& stream) | ParseResult<MemorySection::Memory> MemorySection::Memory::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Memory"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Memory"sv); | ||||||
|     auto type = MemoryType::parse(stream); |     auto type = MemoryType::parse(stream); | ||||||
|  | @ -901,7 +901,7 @@ ParseResult<MemorySection::Memory> MemorySection::Memory::parse(Core::Stream::St | ||||||
|     return Memory { type.release_value() }; |     return Memory { type.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<MemorySection> MemorySection::parse(Core::Stream::Stream& stream) | ParseResult<MemorySection> MemorySection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemorySection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemorySection"sv); | ||||||
|     auto memories = parse_vector<Memory>(stream); |     auto memories = parse_vector<Memory>(stream); | ||||||
|  | @ -910,7 +910,7 @@ ParseResult<MemorySection> MemorySection::parse(Core::Stream::Stream& stream) | ||||||
|     return MemorySection { memories.release_value() }; |     return MemorySection { memories.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<Expression> Expression::parse(Core::Stream::Stream& stream) | ParseResult<Expression> Expression::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Expression"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Expression"sv); | ||||||
|     InstructionPointer ip { 0 }; |     InstructionPointer ip { 0 }; | ||||||
|  | @ -921,7 +921,7 @@ ParseResult<Expression> Expression::parse(Core::Stream::Stream& stream) | ||||||
|     return Expression { move(instructions.value().values) }; |     return Expression { move(instructions.value().values) }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<GlobalSection::Global> GlobalSection::Global::parse(Core::Stream::Stream& stream) | ParseResult<GlobalSection::Global> GlobalSection::Global::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Global"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Global"sv); | ||||||
|     auto type = GlobalType::parse(stream); |     auto type = GlobalType::parse(stream); | ||||||
|  | @ -933,7 +933,7 @@ ParseResult<GlobalSection::Global> GlobalSection::Global::parse(Core::Stream::St | ||||||
|     return Global { type.release_value(), exprs.release_value() }; |     return Global { type.release_value(), exprs.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<GlobalSection> GlobalSection::parse(Core::Stream::Stream& stream) | ParseResult<GlobalSection> GlobalSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalSection"sv); | ||||||
|     auto result = parse_vector<Global>(stream); |     auto result = parse_vector<Global>(stream); | ||||||
|  | @ -942,7 +942,7 @@ ParseResult<GlobalSection> GlobalSection::parse(Core::Stream::Stream& stream) | ||||||
|     return GlobalSection { result.release_value() }; |     return GlobalSection { result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ExportSection::Export> ExportSection::Export::parse(Core::Stream::Stream& stream) | ParseResult<ExportSection::Export> ExportSection::Export::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Export"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Export"sv); | ||||||
|     auto name = parse_name(stream); |     auto name = parse_name(stream); | ||||||
|  | @ -973,7 +973,7 @@ ParseResult<ExportSection::Export> ExportSection::Export::parse(Core::Stream::St | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ExportSection> ExportSection::parse(Core::Stream::Stream& stream) | ParseResult<ExportSection> ExportSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ExportSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ExportSection"sv); | ||||||
|     auto result = parse_vector<Export>(stream); |     auto result = parse_vector<Export>(stream); | ||||||
|  | @ -982,7 +982,7 @@ ParseResult<ExportSection> ExportSection::parse(Core::Stream::Stream& stream) | ||||||
|     return ExportSection { result.release_value() }; |     return ExportSection { result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<StartSection::StartFunction> StartSection::StartFunction::parse(Core::Stream::Stream& stream) | ParseResult<StartSection::StartFunction> StartSection::StartFunction::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartFunction"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartFunction"sv); | ||||||
|     auto index = GenericIndexParser<FunctionIndex>::parse(stream); |     auto index = GenericIndexParser<FunctionIndex>::parse(stream); | ||||||
|  | @ -991,7 +991,7 @@ ParseResult<StartSection::StartFunction> StartSection::StartFunction::parse(Core | ||||||
|     return StartFunction { index.release_value() }; |     return StartFunction { index.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<StartSection> StartSection::parse(Core::Stream::Stream& stream) | ParseResult<StartSection> StartSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartSection"sv); | ||||||
|     auto result = StartFunction::parse(stream); |     auto result = StartFunction::parse(stream); | ||||||
|  | @ -1000,7 +1000,7 @@ ParseResult<StartSection> StartSection::parse(Core::Stream::Stream& stream) | ||||||
|     return StartSection { result.release_value() }; |     return StartSection { result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType0> ElementSection::SegmentType0::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType0> ElementSection::SegmentType0::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     auto expression = Expression::parse(stream); |     auto expression = Expression::parse(stream); | ||||||
|     if (expression.is_error()) |     if (expression.is_error()) | ||||||
|  | @ -1012,7 +1012,7 @@ ParseResult<ElementSection::SegmentType0> ElementSection::SegmentType0::parse(Co | ||||||
|     return SegmentType0 { indices.release_value(), Active { 0, expression.release_value() } }; |     return SegmentType0 { indices.release_value(), Active { 0, expression.release_value() } }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType1> ElementSection::SegmentType1::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType1> ElementSection::SegmentType1::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     auto kind_or_error = stream.read_value<u8>(); |     auto kind_or_error = stream.read_value<u8>(); | ||||||
|     if (kind_or_error.is_error()) |     if (kind_or_error.is_error()) | ||||||
|  | @ -1028,49 +1028,49 @@ ParseResult<ElementSection::SegmentType1> ElementSection::SegmentType1::parse(Co | ||||||
|     return SegmentType1 { indices.release_value() }; |     return SegmentType1 { indices.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType2> ElementSection::SegmentType2::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType2> ElementSection::SegmentType2::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     dbgln("Type 2"); |     dbgln("Type 2"); | ||||||
|     (void)stream; |     (void)stream; | ||||||
|     return ParseError::NotImplemented; |     return ParseError::NotImplemented; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType3> ElementSection::SegmentType3::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType3> ElementSection::SegmentType3::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     dbgln("Type 3"); |     dbgln("Type 3"); | ||||||
|     (void)stream; |     (void)stream; | ||||||
|     return ParseError::NotImplemented; |     return ParseError::NotImplemented; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType4> ElementSection::SegmentType4::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType4> ElementSection::SegmentType4::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     dbgln("Type 4"); |     dbgln("Type 4"); | ||||||
|     (void)stream; |     (void)stream; | ||||||
|     return ParseError::NotImplemented; |     return ParseError::NotImplemented; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType5> ElementSection::SegmentType5::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType5> ElementSection::SegmentType5::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     dbgln("Type 5"); |     dbgln("Type 5"); | ||||||
|     (void)stream; |     (void)stream; | ||||||
|     return ParseError::NotImplemented; |     return ParseError::NotImplemented; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType6> ElementSection::SegmentType6::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType6> ElementSection::SegmentType6::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     dbgln("Type 6"); |     dbgln("Type 6"); | ||||||
|     (void)stream; |     (void)stream; | ||||||
|     return ParseError::NotImplemented; |     return ParseError::NotImplemented; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::SegmentType7> ElementSection::SegmentType7::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::SegmentType7> ElementSection::SegmentType7::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     dbgln("Type 7"); |     dbgln("Type 7"); | ||||||
|     (void)stream; |     (void)stream; | ||||||
|     return ParseError::NotImplemented; |     return ParseError::NotImplemented; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection::Element> ElementSection::Element::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection::Element> ElementSection::Element::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Element"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Element"sv); | ||||||
|     auto tag_or_error = stream.read_value<u8>(); |     auto tag_or_error = stream.read_value<u8>(); | ||||||
|  | @ -1139,7 +1139,7 @@ ParseResult<ElementSection::Element> ElementSection::Element::parse(Core::Stream | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<ElementSection> ElementSection::parse(Core::Stream::Stream& stream) | ParseResult<ElementSection> ElementSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ElementSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("ElementSection"sv); | ||||||
|     auto result = parse_vector<Element>(stream); |     auto result = parse_vector<Element>(stream); | ||||||
|  | @ -1148,7 +1148,7 @@ ParseResult<ElementSection> ElementSection::parse(Core::Stream::Stream& stream) | ||||||
|     return ElementSection { result.release_value() }; |     return ElementSection { result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<Locals> Locals::parse(Core::Stream::Stream& stream) | ParseResult<Locals> Locals::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Locals"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Locals"sv); | ||||||
|     size_t count; |     size_t count; | ||||||
|  | @ -1166,7 +1166,7 @@ ParseResult<Locals> Locals::parse(Core::Stream::Stream& stream) | ||||||
|     return Locals { static_cast<u32>(count), type.release_value() }; |     return Locals { static_cast<u32>(count), type.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<CodeSection::Func> CodeSection::Func::parse(Core::Stream::Stream& stream) | ParseResult<CodeSection::Func> CodeSection::Func::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Func"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Func"sv); | ||||||
|     auto locals = parse_vector<Locals>(stream); |     auto locals = parse_vector<Locals>(stream); | ||||||
|  | @ -1178,7 +1178,7 @@ ParseResult<CodeSection::Func> CodeSection::Func::parse(Core::Stream::Stream& st | ||||||
|     return Func { locals.release_value(), body.release_value() }; |     return Func { locals.release_value(), body.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<CodeSection::Code> CodeSection::Code::parse(Core::Stream::Stream& stream) | ParseResult<CodeSection::Code> CodeSection::Code::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Code"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Code"sv); | ||||||
|     size_t size; |     size_t size; | ||||||
|  | @ -1195,7 +1195,7 @@ ParseResult<CodeSection::Code> CodeSection::Code::parse(Core::Stream::Stream& st | ||||||
|     return Code { static_cast<u32>(size), func.release_value() }; |     return Code { static_cast<u32>(size), func.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<CodeSection> CodeSection::parse(Core::Stream::Stream& stream) | ParseResult<CodeSection> CodeSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("CodeSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("CodeSection"sv); | ||||||
|     auto result = parse_vector<Code>(stream); |     auto result = parse_vector<Code>(stream); | ||||||
|  | @ -1204,7 +1204,7 @@ ParseResult<CodeSection> CodeSection::parse(Core::Stream::Stream& stream) | ||||||
|     return CodeSection { result.release_value() }; |     return CodeSection { result.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<DataSection::Data> DataSection::Data::parse(Core::Stream::Stream& stream) | ParseResult<DataSection::Data> DataSection::Data::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Data"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Data"sv); | ||||||
|     auto tag_or_error = stream.read_value<u8>(); |     auto tag_or_error = stream.read_value<u8>(); | ||||||
|  | @ -1246,7 +1246,7 @@ ParseResult<DataSection::Data> DataSection::Data::parse(Core::Stream::Stream& st | ||||||
|     VERIFY_NOT_REACHED(); |     VERIFY_NOT_REACHED(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<DataSection> DataSection::parse(Core::Stream::Stream& stream) | ParseResult<DataSection> DataSection::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataSection"sv); | ||||||
|     auto data = parse_vector<Data>(stream); |     auto data = parse_vector<Data>(stream); | ||||||
|  | @ -1256,7 +1256,7 @@ ParseResult<DataSection> DataSection::parse(Core::Stream::Stream& stream) | ||||||
|     return DataSection { data.release_value() }; |     return DataSection { data.release_value() }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<DataCountSection> DataCountSection::parse([[maybe_unused]] Core::Stream::Stream& stream) | ParseResult<DataCountSection> DataCountSection::parse([[maybe_unused]] AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataCountSection"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataCountSection"sv); | ||||||
|     u32 value; |     u32 value; | ||||||
|  | @ -1272,7 +1272,7 @@ ParseResult<DataCountSection> DataCountSection::parse([[maybe_unused]] Core::Str | ||||||
|     return DataCountSection { value }; |     return DataCountSection { value }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ParseResult<Module> Module::parse(Core::Stream::Stream& stream) | ParseResult<Module> Module::parse(AK::Stream& stream) | ||||||
| { | { | ||||||
|     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Module"sv); |     ScopeLogger<WASM_BINPARSER_DEBUG> logger("Module"sv); | ||||||
|     u8 buf[4]; |     u8 buf[4]; | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ DeprecatedString instruction_name(OpCode const& opcode); | ||||||
| Optional<OpCode> instruction_from_name(StringView name); | Optional<OpCode> instruction_from_name(StringView name); | ||||||
| 
 | 
 | ||||||
| struct Printer { | struct Printer { | ||||||
|     explicit Printer(Core::Stream::Stream& stream, size_t initial_indent = 0) |     explicit Printer(AK::Stream& stream, size_t initial_indent = 0) | ||||||
|         : m_stream(stream) |         : m_stream(stream) | ||||||
|         , m_indent(initial_indent) |         , m_indent(initial_indent) | ||||||
|     { |     { | ||||||
|  | @ -72,7 +72,7 @@ private: | ||||||
|         m_stream.write_entire_buffer(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors(); |         m_stream.write_entire_buffer(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Core::Stream::Stream& m_stream; |     AK::Stream& m_stream; | ||||||
|     size_t m_indent { 0 }; |     size_t m_indent { 0 }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -59,11 +59,11 @@ AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, LabelIndex); | ||||||
| AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, DataIndex); | AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, DataIndex); | ||||||
| AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, InstructionPointer, Arithmetic, Comparison, Flags, Increment); | AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, InstructionPointer, Arithmetic, Comparison, Flags, Increment); | ||||||
| 
 | 
 | ||||||
| ParseError with_eof_check(Core::Stream::Stream const& stream, ParseError error_if_not_eof); | ParseError with_eof_check(AK::Stream const& stream, ParseError error_if_not_eof); | ||||||
| 
 | 
 | ||||||
| template<typename T> | template<typename T> | ||||||
| struct GenericIndexParser { | struct GenericIndexParser { | ||||||
|     static ParseResult<T> parse(Core::Stream::Stream& stream) |     static ParseResult<T> parse(AK::Stream& stream) | ||||||
|     { |     { | ||||||
|         size_t value; |         size_t value; | ||||||
|         Core::Stream::WrapInAKInputStream wrapped_stream { stream }; |         Core::Stream::WrapInAKInputStream wrapped_stream { stream }; | ||||||
|  | @ -73,9 +73,9 @@ struct GenericIndexParser { | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class ReconsumableStream : public Core::Stream::Stream { | class ReconsumableStream : public AK::Stream { | ||||||
| public: | public: | ||||||
|     explicit ReconsumableStream(Core::Stream::Stream& stream) |     explicit ReconsumableStream(AK::Stream& stream) | ||||||
|         : m_stream(stream) |         : m_stream(stream) | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
|  | @ -133,13 +133,13 @@ private: | ||||||
|         m_stream.close(); |         m_stream.close(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Core::Stream::Stream& m_stream; |     AK::Stream& m_stream; | ||||||
|     Vector<u8, 8> m_buffer; |     Vector<u8, 8> m_buffer; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class ConstrainedStream : public Core::Stream::Stream { | class ConstrainedStream : public AK::Stream { | ||||||
| public: | public: | ||||||
|     explicit ConstrainedStream(Core::Stream::Stream& stream, size_t size) |     explicit ConstrainedStream(AK::Stream& stream, size_t size) | ||||||
|         : m_stream(stream) |         : m_stream(stream) | ||||||
|         , m_bytes_left(size) |         , m_bytes_left(size) | ||||||
|     { |     { | ||||||
|  | @ -182,7 +182,7 @@ private: | ||||||
|         m_stream.close(); |         m_stream.close(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Core::Stream::Stream& m_stream; |     AK::Stream& m_stream; | ||||||
|     size_t m_bytes_left { 0 }; |     size_t m_bytes_left { 0 }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -211,7 +211,7 @@ public: | ||||||
|     auto is_numeric() const { return !is_reference(); } |     auto is_numeric() const { return !is_reference(); } | ||||||
|     auto kind() const { return m_kind; } |     auto kind() const { return m_kind; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<ValueType> parse(Core::Stream::Stream& stream); |     static ParseResult<ValueType> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     static DeprecatedString kind_name(Kind kind) |     static DeprecatedString kind_name(Kind kind) | ||||||
|     { |     { | ||||||
|  | @ -250,7 +250,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto const& types() const { return m_types; } |     auto const& types() const { return m_types; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<ResultType> parse(Core::Stream::Stream& stream); |     static ParseResult<ResultType> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<ValueType> m_types; |     Vector<ValueType> m_types; | ||||||
|  | @ -268,7 +268,7 @@ public: | ||||||
|     auto& parameters() const { return m_parameters; } |     auto& parameters() const { return m_parameters; } | ||||||
|     auto& results() const { return m_results; } |     auto& results() const { return m_results; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<FunctionType> parse(Core::Stream::Stream& stream); |     static ParseResult<FunctionType> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<ValueType> m_parameters; |     Vector<ValueType> m_parameters; | ||||||
|  | @ -287,7 +287,7 @@ public: | ||||||
|     auto min() const { return m_min; } |     auto min() const { return m_min; } | ||||||
|     auto& max() const { return m_max; } |     auto& max() const { return m_max; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<Limits> parse(Core::Stream::Stream& stream); |     static ParseResult<Limits> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     u32 m_min { 0 }; |     u32 m_min { 0 }; | ||||||
|  | @ -304,7 +304,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& limits() const { return m_limits; } |     auto& limits() const { return m_limits; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<MemoryType> parse(Core::Stream::Stream& stream); |     static ParseResult<MemoryType> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Limits m_limits; |     Limits m_limits; | ||||||
|  | @ -323,7 +323,7 @@ public: | ||||||
|     auto& limits() const { return m_limits; } |     auto& limits() const { return m_limits; } | ||||||
|     auto& element_type() const { return m_element_type; } |     auto& element_type() const { return m_element_type; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<TableType> parse(Core::Stream::Stream& stream); |     static ParseResult<TableType> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     ValueType m_element_type; |     ValueType m_element_type; | ||||||
|  | @ -342,7 +342,7 @@ public: | ||||||
|     auto& type() const { return m_type; } |     auto& type() const { return m_type; } | ||||||
|     auto is_mutable() const { return m_is_mutable; } |     auto is_mutable() const { return m_is_mutable; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<GlobalType> parse(Core::Stream::Stream& stream); |     static ParseResult<GlobalType> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     ValueType m_type; |     ValueType m_type; | ||||||
|  | @ -388,7 +388,7 @@ public: | ||||||
|         return m_type_index; |         return m_type_index; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<BlockType> parse(Core::Stream::Stream& stream); |     static ParseResult<BlockType> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Kind m_kind { Empty }; |     Kind m_kind { Empty }; | ||||||
|  | @ -452,7 +452,7 @@ public: | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<Vector<Instruction>> parse(Core::Stream::Stream& stream, InstructionPointer& ip); |     static ParseResult<Vector<Instruction>> parse(AK::Stream& stream, InstructionPointer& ip); | ||||||
| 
 | 
 | ||||||
|     auto& opcode() const { return m_opcode; } |     auto& opcode() const { return m_opcode; } | ||||||
|     auto& arguments() const { return m_arguments; } |     auto& arguments() const { return m_arguments; } | ||||||
|  | @ -499,7 +499,7 @@ public: | ||||||
|     auto& name() const { return m_name; } |     auto& name() const { return m_name; } | ||||||
|     auto& contents() const { return m_contents; } |     auto& contents() const { return m_contents; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<CustomSection> parse(Core::Stream::Stream& stream); |     static ParseResult<CustomSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     DeprecatedString m_name; |     DeprecatedString m_name; | ||||||
|  | @ -517,7 +517,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& types() const { return m_types; } |     auto& types() const { return m_types; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<TypeSection> parse(Core::Stream::Stream& stream); |     static ParseResult<TypeSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<FunctionType> m_types; |     Vector<FunctionType> m_types; | ||||||
|  | @ -539,7 +539,7 @@ public: | ||||||
|         auto& name() const { return m_name; } |         auto& name() const { return m_name; } | ||||||
|         auto& description() const { return m_description; } |         auto& description() const { return m_description; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Import> parse(Core::Stream::Stream& stream); |         static ParseResult<Import> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         template<typename T> |         template<typename T> | ||||||
|  | @ -566,7 +566,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& imports() const { return m_imports; } |     auto& imports() const { return m_imports; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<ImportSection> parse(Core::Stream::Stream& stream); |     static ParseResult<ImportSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Import> m_imports; |     Vector<Import> m_imports; | ||||||
|  | @ -583,7 +583,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& types() const { return m_types; } |     auto& types() const { return m_types; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<FunctionSection> parse(Core::Stream::Stream& stream); |     static ParseResult<FunctionSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<TypeIndex> m_types; |     Vector<TypeIndex> m_types; | ||||||
|  | @ -600,7 +600,7 @@ public: | ||||||
| 
 | 
 | ||||||
|         auto& type() const { return m_type; } |         auto& type() const { return m_type; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Table> parse(Core::Stream::Stream& stream); |         static ParseResult<Table> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         TableType m_type; |         TableType m_type; | ||||||
|  | @ -616,7 +616,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& tables() const { return m_tables; }; |     auto& tables() const { return m_tables; }; | ||||||
| 
 | 
 | ||||||
|     static ParseResult<TableSection> parse(Core::Stream::Stream& stream); |     static ParseResult<TableSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Table> m_tables; |     Vector<Table> m_tables; | ||||||
|  | @ -633,7 +633,7 @@ public: | ||||||
| 
 | 
 | ||||||
|         auto& type() const { return m_type; } |         auto& type() const { return m_type; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Memory> parse(Core::Stream::Stream& stream); |         static ParseResult<Memory> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         MemoryType m_type; |         MemoryType m_type; | ||||||
|  | @ -649,7 +649,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& memories() const { return m_memories; } |     auto& memories() const { return m_memories; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<MemorySection> parse(Core::Stream::Stream& stream); |     static ParseResult<MemorySection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Memory> m_memories; |     Vector<Memory> m_memories; | ||||||
|  | @ -664,7 +664,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& instructions() const { return m_instructions; } |     auto& instructions() const { return m_instructions; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<Expression> parse(Core::Stream::Stream& stream); |     static ParseResult<Expression> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Instruction> m_instructions; |     Vector<Instruction> m_instructions; | ||||||
|  | @ -683,7 +683,7 @@ public: | ||||||
|         auto& type() const { return m_type; } |         auto& type() const { return m_type; } | ||||||
|         auto& expression() const { return m_expression; } |         auto& expression() const { return m_expression; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Global> parse(Core::Stream::Stream& stream); |         static ParseResult<Global> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         GlobalType m_type; |         GlobalType m_type; | ||||||
|  | @ -700,7 +700,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& entries() const { return m_entries; } |     auto& entries() const { return m_entries; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<GlobalSection> parse(Core::Stream::Stream& stream); |     static ParseResult<GlobalSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Global> m_entries; |     Vector<Global> m_entries; | ||||||
|  | @ -722,7 +722,7 @@ public: | ||||||
|         auto& name() const { return m_name; } |         auto& name() const { return m_name; } | ||||||
|         auto& description() const { return m_description; } |         auto& description() const { return m_description; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Export> parse(Core::Stream::Stream& stream); |         static ParseResult<Export> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         DeprecatedString m_name; |         DeprecatedString m_name; | ||||||
|  | @ -738,7 +738,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& entries() const { return m_entries; } |     auto& entries() const { return m_entries; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<ExportSection> parse(Core::Stream::Stream& stream); |     static ParseResult<ExportSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Export> m_entries; |     Vector<Export> m_entries; | ||||||
|  | @ -755,7 +755,7 @@ public: | ||||||
| 
 | 
 | ||||||
|         auto& index() const { return m_index; } |         auto& index() const { return m_index; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<StartFunction> parse(Core::Stream::Stream& stream); |         static ParseResult<StartFunction> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         FunctionIndex m_index; |         FunctionIndex m_index; | ||||||
|  | @ -770,7 +770,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& function() const { return m_function; } |     auto& function() const { return m_function; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<StartSection> parse(Core::Stream::Stream& stream); |     static ParseResult<StartSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     StartFunction m_function; |     StartFunction m_function; | ||||||
|  | @ -789,43 +789,43 @@ public: | ||||||
| 
 | 
 | ||||||
|     struct SegmentType0 { |     struct SegmentType0 { | ||||||
|         // FIXME: Implement me!
 |         // FIXME: Implement me!
 | ||||||
|         static ParseResult<SegmentType0> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType0> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|         Vector<FunctionIndex> function_indices; |         Vector<FunctionIndex> function_indices; | ||||||
|         Active mode; |         Active mode; | ||||||
|     }; |     }; | ||||||
|     struct SegmentType1 { |     struct SegmentType1 { | ||||||
|         static ParseResult<SegmentType1> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType1> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|         Vector<FunctionIndex> function_indices; |         Vector<FunctionIndex> function_indices; | ||||||
|     }; |     }; | ||||||
|     struct SegmentType2 { |     struct SegmentType2 { | ||||||
|         // FIXME: Implement me!
 |         // FIXME: Implement me!
 | ||||||
|         static ParseResult<SegmentType2> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType2> parse(AK::Stream& stream); | ||||||
|     }; |     }; | ||||||
|     struct SegmentType3 { |     struct SegmentType3 { | ||||||
|         // FIXME: Implement me!
 |         // FIXME: Implement me!
 | ||||||
|         static ParseResult<SegmentType3> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType3> parse(AK::Stream& stream); | ||||||
|     }; |     }; | ||||||
|     struct SegmentType4 { |     struct SegmentType4 { | ||||||
|         // FIXME: Implement me!
 |         // FIXME: Implement me!
 | ||||||
|         static ParseResult<SegmentType4> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType4> parse(AK::Stream& stream); | ||||||
|     }; |     }; | ||||||
|     struct SegmentType5 { |     struct SegmentType5 { | ||||||
|         // FIXME: Implement me!
 |         // FIXME: Implement me!
 | ||||||
|         static ParseResult<SegmentType5> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType5> parse(AK::Stream& stream); | ||||||
|     }; |     }; | ||||||
|     struct SegmentType6 { |     struct SegmentType6 { | ||||||
|         // FIXME: Implement me!
 |         // FIXME: Implement me!
 | ||||||
|         static ParseResult<SegmentType6> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType6> parse(AK::Stream& stream); | ||||||
|     }; |     }; | ||||||
|     struct SegmentType7 { |     struct SegmentType7 { | ||||||
|         // FIXME: Implement me!
 |         // FIXME: Implement me!
 | ||||||
|         static ParseResult<SegmentType7> parse(Core::Stream::Stream& stream); |         static ParseResult<SegmentType7> parse(AK::Stream& stream); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     struct Element { |     struct Element { | ||||||
|         static ParseResult<Element> parse(Core::Stream::Stream&); |         static ParseResult<Element> parse(AK::Stream&); | ||||||
| 
 | 
 | ||||||
|         ValueType type; |         ValueType type; | ||||||
|         Vector<Expression> init; |         Vector<Expression> init; | ||||||
|  | @ -841,7 +841,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& segments() const { return m_segments; } |     auto& segments() const { return m_segments; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<ElementSection> parse(Core::Stream::Stream& stream); |     static ParseResult<ElementSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Element> m_segments; |     Vector<Element> m_segments; | ||||||
|  | @ -859,7 +859,7 @@ public: | ||||||
|     auto n() const { return m_n; } |     auto n() const { return m_n; } | ||||||
|     auto& type() const { return m_type; } |     auto& type() const { return m_type; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<Locals> parse(Core::Stream::Stream& stream); |     static ParseResult<Locals> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     u32 m_n { 0 }; |     u32 m_n { 0 }; | ||||||
|  | @ -880,7 +880,7 @@ public: | ||||||
|         auto& locals() const { return m_locals; } |         auto& locals() const { return m_locals; } | ||||||
|         auto& body() const { return m_body; } |         auto& body() const { return m_body; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Func> parse(Core::Stream::Stream& stream); |         static ParseResult<Func> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         Vector<Locals> m_locals; |         Vector<Locals> m_locals; | ||||||
|  | @ -897,7 +897,7 @@ public: | ||||||
|         auto size() const { return m_size; } |         auto size() const { return m_size; } | ||||||
|         auto& func() const { return m_func; } |         auto& func() const { return m_func; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Code> parse(Core::Stream::Stream& stream); |         static ParseResult<Code> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         u32 m_size { 0 }; |         u32 m_size { 0 }; | ||||||
|  | @ -913,7 +913,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& functions() const { return m_functions; } |     auto& functions() const { return m_functions; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<CodeSection> parse(Core::Stream::Stream& stream); |     static ParseResult<CodeSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Code> m_functions; |     Vector<Code> m_functions; | ||||||
|  | @ -940,7 +940,7 @@ public: | ||||||
| 
 | 
 | ||||||
|         auto& value() const { return m_value; } |         auto& value() const { return m_value; } | ||||||
| 
 | 
 | ||||||
|         static ParseResult<Data> parse(Core::Stream::Stream& stream); |         static ParseResult<Data> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         Value m_value; |         Value m_value; | ||||||
|  | @ -955,7 +955,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& data() const { return m_data; } |     auto& data() const { return m_data; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<DataSection> parse(Core::Stream::Stream& stream); |     static ParseResult<DataSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Vector<Data> m_data; |     Vector<Data> m_data; | ||||||
|  | @ -972,7 +972,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     auto& count() const { return m_count; } |     auto& count() const { return m_count; } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<DataCountSection> parse(Core::Stream::Stream& stream); |     static ParseResult<DataCountSection> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     Optional<u32> m_count; |     Optional<u32> m_count; | ||||||
|  | @ -1067,7 +1067,7 @@ public: | ||||||
|     StringView validation_error() const { return *m_validation_error; } |     StringView validation_error() const { return *m_validation_error; } | ||||||
|     void set_validation_error(DeprecatedString error) { m_validation_error = move(error); } |     void set_validation_error(DeprecatedString error) { m_validation_error = move(error); } | ||||||
| 
 | 
 | ||||||
|     static ParseResult<Module> parse(Core::Stream::Stream& stream); |     static ParseResult<Module> parse(AK::Stream& stream); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     bool populate_sections(); |     bool populate_sections(); | ||||||
|  |  | ||||||
|  | @ -61,7 +61,7 @@ public: | ||||||
|     virtual void set_should_buffer_all_input(bool) = 0; |     virtual void set_should_buffer_all_input(bool) = 0; | ||||||
|     virtual bool stop() = 0; |     virtual bool stop() = 0; | ||||||
| 
 | 
 | ||||||
|     virtual void stream_into(Core::Stream::Stream&) = 0; |     virtual void stream_into(AK::Stream&) = 0; | ||||||
| 
 | 
 | ||||||
|     Function<void(bool success, u32 total_size, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code, ReadonlyBytes payload)> on_buffered_request_finish; |     Function<void(bool success, u32 total_size, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code, ReadonlyBytes payload)> on_buffered_request_finish; | ||||||
|     Function<void(bool success, u32 total_size)> on_finish; |     Function<void(bool success, u32 total_size)> on_finish; | ||||||
|  |  | ||||||
|  | @ -64,7 +64,7 @@ bool RequestServerRequestAdapter::stop() | ||||||
|     return m_request->stop(); |     return m_request->stop(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void RequestServerRequestAdapter::stream_into(Core::Stream::Stream& stream) | void RequestServerRequestAdapter::stream_into(AK::Stream& stream) | ||||||
| { | { | ||||||
|     m_request->stream_into(stream); |     m_request->stream_into(stream); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ public: | ||||||
|     virtual void set_should_buffer_all_input(bool) override; |     virtual void set_should_buffer_all_input(bool) override; | ||||||
|     virtual bool stop() override; |     virtual bool stop() override; | ||||||
| 
 | 
 | ||||||
|     virtual void stream_into(Core::Stream::Stream&) override; |     virtual void stream_into(AK::Stream&) override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     RequestServerRequestAdapter(NonnullRefPtr<Protocol::Request>); |     RequestServerRequestAdapter(NonnullRefPtr<Protocol::Request>); | ||||||
|  |  | ||||||
|  | @ -175,7 +175,7 @@ ErrorOr<bool> Client::handle_request(ReadonlyBytes raw_request) | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<void> Client::send_response(Core::Stream::Stream& response, HTTP::HttpRequest const& request, ContentInfo content_info) | ErrorOr<void> Client::send_response(AK::Stream& response, HTTP::HttpRequest const& request, ContentInfo content_info) | ||||||
| { | { | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|     builder.append("HTTP/1.0 200 OK\r\n"sv); |     builder.append("HTTP/1.0 200 OK\r\n"sv); | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ private: | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     ErrorOr<bool> handle_request(ReadonlyBytes); |     ErrorOr<bool> handle_request(ReadonlyBytes); | ||||||
|     ErrorOr<void> send_response(Core::Stream::Stream&, HTTP::HttpRequest const&, ContentInfo); |     ErrorOr<void> send_response(AK::Stream&, HTTP::HttpRequest const&, ContentInfo); | ||||||
|     ErrorOr<void> send_redirect(StringView redirect, HTTP::HttpRequest const&); |     ErrorOr<void> send_redirect(StringView redirect, HTTP::HttpRequest const&); | ||||||
|     ErrorOr<void> send_error_response(unsigned code, HTTP::HttpRequest const&, Vector<String> const& headers = {}); |     ErrorOr<void> send_error_response(unsigned code, HTTP::HttpRequest const&, Vector<String> const& headers = {}); | ||||||
|     void die(); |     void die(); | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ static ErrorOr<bool> format_file(StringView path, bool inplace) | ||||||
|     if (inplace && !read_from_stdin) { |     if (inplace && !read_from_stdin) { | ||||||
|         if (formatted_gml == contents) |         if (formatted_gml == contents) | ||||||
|             return true; |             return true; | ||||||
|         TRY(file->seek(0, Core::Stream::SeekMode::SetPosition)); |         TRY(file->seek(0, SeekMode::SetPosition)); | ||||||
|         TRY(file->truncate(0)); |         TRY(file->truncate(0)); | ||||||
|         TRY(file->write(formatted_gml.bytes())); |         TRY(file->write(formatted_gml.bytes())); | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|  | @ -10,7 +10,7 @@ | ||||||
| #include <LibMain/Main.h> | #include <LibMain/Main.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> decompress_file(NonnullOwnPtr<Core::Stream::File> input_stream, Core::Stream::Stream& output_stream) | static ErrorOr<void> decompress_file(NonnullOwnPtr<Core::Stream::File> input_stream, AK::Stream& output_stream) | ||||||
| { | { | ||||||
|     auto gzip_stream = Compress::GzipDecompressor { move(input_stream) }; |     auto gzip_stream = Compress::GzipDecompressor { move(input_stream) }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -336,7 +336,7 @@ public: | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         virtual void stream_into(Core::Stream::Stream&) override |         virtual void stream_into(AK::Stream&) override | ||||||
|         { |         { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -415,7 +415,7 @@ public: | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         virtual void stream_into(Core::Stream::Stream&) override |         virtual void stream_into(AK::Stream&) override | ||||||
|         { |         { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -484,7 +484,7 @@ public: | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         virtual void stream_into(Core::Stream::Stream&) override |         virtual void stream_into(AK::Stream&) override | ||||||
|         { |         { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -39,7 +39,7 @@ ErrorOr<int> serenity_main(Main::Arguments args) | ||||||
| 
 | 
 | ||||||
|     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read)); |     auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read)); | ||||||
|     if (seek_to.has_value()) |     if (seek_to.has_value()) | ||||||
|         TRY(file->seek(seek_to.value(), Core::Stream::SeekMode::SetPosition)); |         TRY(file->seek(seek_to.value(), SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|     auto print_line = [](Bytes line) { |     auto print_line = [](Bytes line) { | ||||||
|         VERIFY(line.size() <= LINE_LENGTH_BYTES); |         VERIFY(line.size() <= LINE_LENGTH_BYTES); | ||||||
|  |  | ||||||
|  | @ -84,7 +84,7 @@ static DeprecatedString s_history_path = DeprecatedString::formatted("{}/.js-his | ||||||
| static int s_repl_line_level = 0; | static int s_repl_line_level = 0; | ||||||
| static bool s_fail_repl = false; | static bool s_fail_repl = false; | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> print(JS::Value value, Core::Stream::Stream& stream) | static ErrorOr<void> print(JS::Value value, AK::Stream& stream) | ||||||
| { | { | ||||||
|     JS::PrintContext print_context { .vm = *g_vm, .stream = stream, .strip_ansi = s_strip_ansi }; |     JS::PrintContext print_context { .vm = *g_vm, .stream = stream, .strip_ansi = s_strip_ansi }; | ||||||
|     return JS::print(value, print_context); |     return JS::print(value, print_context); | ||||||
|  |  | ||||||
|  | @ -104,9 +104,9 @@ private: | ||||||
| 
 | 
 | ||||||
| /// Wraps a stream to silently ignore writes when the condition isn't true.
 | /// Wraps a stream to silently ignore writes when the condition isn't true.
 | ||||||
| template<typename ConditionT> | template<typename ConditionT> | ||||||
| class ConditionalOutputStream final : public Core::Stream::Stream { | class ConditionalOutputStream final : public AK::Stream { | ||||||
| public: | public: | ||||||
|     ConditionalOutputStream(ConditionT&& condition, MaybeOwned<Core::Stream::Stream> stream) |     ConditionalOutputStream(ConditionT&& condition, MaybeOwned<AK::Stream> stream) | ||||||
|         : m_stream(move(stream)) |         : m_stream(move(stream)) | ||||||
|         , m_condition(condition) |         , m_condition(condition) | ||||||
|     { |     { | ||||||
|  | @ -141,7 +141,7 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     MaybeOwned<Core::Stream::Stream> m_stream; |     MaybeOwned<AK::Stream> m_stream; | ||||||
|     ConditionT m_condition; |     ConditionT m_condition; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ | ||||||
| 
 | 
 | ||||||
| static ErrorOr<void> tail_from_pos(Core::Stream::File& file, off_t startline) | static ErrorOr<void> tail_from_pos(Core::Stream::File& file, off_t startline) | ||||||
| { | { | ||||||
|     TRY(file.seek(startline + 1, Core::Stream::SeekMode::SetPosition)); |     TRY(file.seek(startline + 1, SeekMode::SetPosition)); | ||||||
|     auto buffer = TRY(file.read_until_eof()); |     auto buffer = TRY(file.read_until_eof()); | ||||||
|     out("{}", StringView { buffer }); |     out("{}", StringView { buffer }); | ||||||
|     return {}; |     return {}; | ||||||
|  | @ -24,13 +24,13 @@ static ErrorOr<off_t> find_seek_pos(Core::Stream::File& file, int wanted_lines) | ||||||
| { | { | ||||||
|     // Rather than reading the whole file, start at the end and work backwards,
 |     // Rather than reading the whole file, start at the end and work backwards,
 | ||||||
|     // stopping when we've found the number of lines we want.
 |     // stopping when we've found the number of lines we want.
 | ||||||
|     off_t pos = TRY(file.seek(0, Core::Stream::SeekMode::FromEndPosition)); |     off_t pos = TRY(file.seek(0, SeekMode::FromEndPosition)); | ||||||
| 
 | 
 | ||||||
|     off_t end = pos; |     off_t end = pos; | ||||||
|     int lines = 0; |     int lines = 0; | ||||||
| 
 | 
 | ||||||
|     for (; pos >= 0; pos--) { |     for (; pos >= 0; pos--) { | ||||||
|         TRY(file.seek(pos, Core::Stream::SeekMode::SetPosition)); |         TRY(file.seek(pos, SeekMode::SetPosition)); | ||||||
| 
 | 
 | ||||||
|         if (file.is_eof()) |         if (file.is_eof()) | ||||||
|             break; |             break; | ||||||
|  | @ -102,7 +102,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|     TRY(tail_from_pos(*f, pos)); |     TRY(tail_from_pos(*f, pos)); | ||||||
| 
 | 
 | ||||||
|     if (follow) { |     if (follow) { | ||||||
|         TRY(f->seek(0, Core::Stream::SeekMode::FromEndPosition)); |         TRY(f->seek(0, SeekMode::FromEndPosition)); | ||||||
| 
 | 
 | ||||||
|         Core::EventLoop event_loop; |         Core::EventLoop event_loop; | ||||||
|         auto watcher = TRY(Core::FileWatcher::create()); |         auto watcher = TRY(Core::FileWatcher::create()); | ||||||
|  | @ -118,7 +118,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|                 auto bytes = buffer_or_error.value().bytes(); |                 auto bytes = buffer_or_error.value().bytes(); | ||||||
|                 out("{}", StringView { bytes }); |                 out("{}", StringView { bytes }); | ||||||
| 
 | 
 | ||||||
|                 auto potential_error = f->seek(0, Core::Stream::SeekMode::FromEndPosition); |                 auto potential_error = f->seek(0, SeekMode::FromEndPosition); | ||||||
|                 if (potential_error.is_error()) { |                 if (potential_error.is_error()) { | ||||||
|                     auto error = potential_error.error(); |                     auto error = potential_error.error(); | ||||||
|                     warnln(error.string_literal()); |                     warnln(error.string_literal()); | ||||||
|  |  | ||||||
|  | @ -64,7 +64,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|         if (!directory.is_empty()) |         if (!directory.is_empty()) | ||||||
|             TRY(Core::System::chdir(directory)); |             TRY(Core::System::chdir(directory)); | ||||||
| 
 | 
 | ||||||
|         NonnullOwnPtr<Core::Stream::Stream> input_stream = TRY(Core::Stream::File::open_file_or_standard_stream(archive_file, Core::Stream::OpenMode::Read)); |         NonnullOwnPtr<AK::Stream> input_stream = TRY(Core::Stream::File::open_file_or_standard_stream(archive_file, Core::Stream::OpenMode::Read)); | ||||||
| 
 | 
 | ||||||
|         if (gzip) |         if (gzip) | ||||||
|             input_stream = make<Compress::GzipDecompressor>(move(input_stream)); |             input_stream = make<Compress::GzipDecompressor>(move(input_stream)); | ||||||
|  | @ -206,7 +206,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|             return 1; |             return 1; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         NonnullOwnPtr<Core::Stream::Stream> output_stream = TRY(Core::Stream::File::standard_output()); |         NonnullOwnPtr<AK::Stream> output_stream = TRY(Core::Stream::File::standard_output()); | ||||||
| 
 | 
 | ||||||
|         if (!archive_file.is_empty()) |         if (!archive_file.is_empty()) | ||||||
|             output_stream = TRY(Core::Stream::File::open(archive_file, Core::Stream::OpenMode::Write)); |             output_stream = TRY(Core::Stream::File::open(archive_file, Core::Stream::OpenMode::Write)); | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
|         json.remove(tty_name); |         json.remove(tty_name); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     TRY(file->seek(0, Core::Stream::SeekMode::SetPosition)); |     TRY(file->seek(0, SeekMode::SetPosition)); | ||||||
|     TRY(file->truncate(0)); |     TRY(file->truncate(0)); | ||||||
|     TRY(file->write(json.to_deprecated_string().bytes())); |     TRY(file->write(json.to_deprecated_string().bytes())); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| 
 | 
 | ||||||
| RefPtr<Line::Editor> g_line_editor; | RefPtr<Line::Editor> g_line_editor; | ||||||
| static OwnPtr<Core::Stream::Stream> g_stdout {}; | static OwnPtr<AK::Stream> g_stdout {}; | ||||||
| static OwnPtr<Wasm::Printer> g_printer {}; | static OwnPtr<Wasm::Printer> g_printer {}; | ||||||
| static bool g_continue { false }; | static bool g_continue { false }; | ||||||
| static void (*old_signal)(int); | static void (*old_signal)(int); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Schumacher
						Tim Schumacher