From 8464da143987e290fa3d9ad739b491e6adbffee6 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 22 Jan 2023 05:09:11 +0100 Subject: [PATCH] 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. --- AK/CMakeLists.txt | 1 + AK/Forward.h | 4 + AK/Stream.cpp | 132 +++++++++++++++++ AK/Stream.h | 133 ++++++++++++++++++ Documentation/CodingStyle.md | 2 +- Ladybird/RequestManagerQt.h | 2 +- .../Tools/CodeGenerators/IPCCompiler/main.cpp | 2 +- .../LibUnicode/GenerateUnicodeData.cpp | 4 +- Meta/Lagom/Wasm/js_repl.cpp | 2 +- Tests/LibCore/TestLibCoreIODevice.cpp | 6 +- Tests/LibCore/TestLibCoreStream.cpp | 30 ++-- Userland/Applets/ResourceGraph/main.cpp | 2 +- .../Applications/HexEditor/HexDocument.cpp | 12 +- Userland/Applications/PixelPaint/Image.cpp | 6 +- Userland/Applications/PixelPaint/Image.h | 6 +- .../Applications/Spreadsheet/ExportDialog.cpp | 2 +- .../Applications/Spreadsheet/ExportDialog.h | 2 +- .../Applications/Spreadsheet/Writers/CSV.h | 4 +- .../Applications/Spreadsheet/Writers/XSV.h | 8 +- .../DevTools/UserspaceEmulator/Emulator.cpp | 4 +- .../DevTools/UserspaceEmulator/Emulator.h | 10 +- Userland/DevTools/UserspaceEmulator/main.cpp | 2 +- Userland/Libraries/LibArchive/TarStream.cpp | 6 +- Userland/Libraries/LibArchive/TarStream.h | 12 +- Userland/Libraries/LibArchive/Zip.cpp | 2 +- Userland/Libraries/LibArchive/Zip.h | 10 +- Userland/Libraries/LibAudio/FlacLoader.cpp | 22 +-- Userland/Libraries/LibAudio/FlacLoader.h | 2 +- Userland/Libraries/LibAudio/Loader.cpp | 2 +- Userland/Libraries/LibAudio/Loader.h | 4 +- Userland/Libraries/LibAudio/MP3Loader.cpp | 14 +- Userland/Libraries/LibAudio/MP3Loader.h | 2 +- Userland/Libraries/LibAudio/WavLoader.cpp | 10 +- Userland/Libraries/LibAudio/WavLoader.h | 4 +- Userland/Libraries/LibCompress/Brotli.h | 2 +- Userland/Libraries/LibCompress/Deflate.cpp | 8 +- Userland/Libraries/LibCompress/Deflate.h | 10 +- Userland/Libraries/LibCompress/Gzip.cpp | 10 +- Userland/Libraries/LibCompress/Gzip.h | 14 +- Userland/Libraries/LibCompress/Zlib.cpp | 6 +- Userland/Libraries/LibCompress/Zlib.h | 10 +- Userland/Libraries/LibCore/BitStream.h | 8 +- Userland/Libraries/LibCore/ConfigFile.cpp | 2 +- Userland/Libraries/LibCore/Forward.h | 1 - Userland/Libraries/LibCore/IODevice.h | 7 +- Userland/Libraries/LibCore/MemoryStream.h | 2 +- Userland/Libraries/LibCore/NetworkJob.cpp | 2 +- Userland/Libraries/LibCore/NetworkJob.h | 4 +- .../LibCore/ProcessStatisticsReader.cpp | 4 +- .../LibCore/ProcessStatisticsReader.h | 2 +- Userland/Libraries/LibCore/Stream.cpp | 122 +--------------- Userland/Libraries/LibCore/Stream.h | 130 ++--------------- Userland/Libraries/LibDNS/Name.cpp | 2 +- Userland/Libraries/LibDNS/Name.h | 2 +- .../LibDebug/Dwarf/AddressRanges.cpp | 4 +- .../Libraries/LibDebug/Dwarf/AddressRanges.h | 8 +- .../Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 2 +- Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h | 2 +- .../Libraries/LibDebug/Dwarf/DwarfTypes.h | 2 +- .../Libraries/LibDebug/Dwarf/LineProgram.cpp | 2 +- .../Libraries/LibDebug/Dwarf/LineProgram.h | 6 +- Userland/Libraries/LibGemini/Job.cpp | 2 +- Userland/Libraries/LibGemini/Job.h | 2 +- Userland/Libraries/LibGfx/GIFLoader.cpp | 2 +- Userland/Libraries/LibGfx/JPGLoader.cpp | 22 +-- Userland/Libraries/LibGfx/QOILoader.cpp | 24 ++-- Userland/Libraries/LibGfx/QOILoader.h | 8 +- Userland/Libraries/LibHTTP/HttpsJob.h | 2 +- Userland/Libraries/LibHTTP/Job.cpp | 2 +- Userland/Libraries/LibHTTP/Job.h | 2 +- Userland/Libraries/LibIPC/Decoder.h | 4 +- Userland/Libraries/LibJS/Print.h | 2 +- Userland/Libraries/LibLine/Editor.cpp | 16 +-- Userland/Libraries/LibLine/Editor.h | 2 +- Userland/Libraries/LibLine/VT.h | 14 +- Userland/Libraries/LibProtocol/Request.cpp | 2 +- Userland/Libraries/LibProtocol/Request.h | 6 +- Userland/Libraries/LibSQL/Heap.cpp | 4 +- Userland/Libraries/LibWasm/Parser/Parser.cpp | 96 ++++++------- Userland/Libraries/LibWasm/Printer/Printer.h | 4 +- Userland/Libraries/LibWasm/Types.h | 102 +++++++------- .../Libraries/LibWeb/Loader/ResourceLoader.h | 2 +- .../LibWebView/RequestServerAdapter.cpp | 2 +- .../LibWebView/RequestServerAdapter.h | 2 +- Userland/Services/WebServer/Client.cpp | 2 +- Userland/Services/WebServer/Client.h | 2 +- Userland/Utilities/gml-format.cpp | 2 +- Userland/Utilities/gunzip.cpp | 2 +- Userland/Utilities/headless-browser.cpp | 6 +- Userland/Utilities/hexdump.cpp | 2 +- Userland/Utilities/js.cpp | 2 +- Userland/Utilities/pro.cpp | 6 +- Userland/Utilities/tail.cpp | 10 +- Userland/Utilities/tar.cpp | 4 +- Userland/Utilities/utmpupdate.cpp | 2 +- Userland/Utilities/wasm.cpp | 2 +- 96 files changed, 620 insertions(+), 586 deletions(-) create mode 100644 AK/Stream.cpp create mode 100644 AK/Stream.h diff --git a/AK/CMakeLists.txt b/AK/CMakeLists.txt index 4bb4aecaf9c..00609033056 100644 --- a/AK/CMakeLists.txt +++ b/AK/CMakeLists.txt @@ -19,6 +19,7 @@ set(AK_SOURCES NumberFormat.cpp Random.cpp StackInfo.cpp + Stream.cpp String.cpp StringBuilder.cpp StringFloatingPointConversions.cpp diff --git a/AK/Forward.h b/AK/Forward.h index b0d78152988..d94e7a6fd68 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -35,6 +35,8 @@ class StackInfo; class DeprecatedFlyString; class DeprecatedString; class DeprecatedStringCodePointIterator; +class SeekableStream; +class Stream; class StringBuilder; class StringImpl; class StringView; @@ -183,9 +185,11 @@ using AK::Optional; using AK::OwnPtr; using AK::ReadonlyBytes; using AK::RefPtr; +using AK::SeekableStream; using AK::SinglyLinkedList; using AK::Span; using AK::StackInfo; +using AK::Stream; using AK::String; using AK::StringBuilder; using AK::StringImpl; diff --git a/AK/Stream.cpp b/AK/Stream.cpp new file mode 100644 index 00000000000..19b40e0c2c2 --- /dev/null +++ b/AK/Stream.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2021, sin-ack + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace AK { + +ErrorOr 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 Stream::read_until_eof(size_t block_size) +{ + return read_until_eof_impl(block_size); +} + +ErrorOr 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 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 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 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 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(this)->seek(0, SeekMode::FromCurrentPosition); +} + +ErrorOr 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 SeekableStream::discard(size_t discarded_bytes) +{ + TRY(seek(discarded_bytes, SeekMode::FromCurrentPosition)); + return {}; +} + +} diff --git a/AK/Stream.h b/AK/Stream.h new file mode 100644 index 00000000000..9a039ea8e6c --- /dev/null +++ b/AK/Stream.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2021, sin-ack + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +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 read(Bytes) = 0; + /// Tries to fill the entire buffer through reading. Returns whether the + /// buffer was filled without an error. + virtual ErrorOr 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 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 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 write(ReadonlyBytes) = 0; + /// Same as write, but does not return until either the entire buffer + /// contents are written or an error occurs. + virtual ErrorOr write_entire_buffer(ReadonlyBytes); + + template + requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs>; }) + ErrorOr read_value() + { + return T::read_from_stream(*this); + } + + template + requires(Traits::is_trivially_serializable()) + ErrorOr read_value() + { + alignas(T) u8 buffer[sizeof(T)] = {}; + TRY(read_entire_buffer({ &buffer, sizeof(buffer) })); + return bit_cast(buffer); + } + + template + requires(requires(T t, Stream& stream) { { t.write_to_stream(stream) } -> SameAs>; }) + ErrorOr write_value(T const& value) + { + return value.write_to_stream(*this); + } + + template + requires(Traits::is_trivially_serializable()) + ErrorOr 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 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 seek(i64 offset, SeekMode) = 0; + /// Returns the current position of the file, or an errno in the case of + /// an error. + virtual ErrorOr 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(); + /// Shrinks or extends the stream to the given size. Returns an errno in + /// the case of an error. + virtual ErrorOr 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 discard(size_t discarded_bytes) override; +}; + +} + +#if USING_AK_GLOBALLY +using AK::SeekMode; +#endif diff --git a/Documentation/CodingStyle.md b/Documentation/CodingStyle.md index e09096ae7f6..b526658942d 100644 --- a/Documentation/CodingStyle.md +++ b/Documentation/CodingStyle.md @@ -666,7 +666,7 @@ T* ret = reinterpret_cast(buffer); ``` ```cpp -// Core::Stream::SeekableStream::tell() +// SeekableStream::tell() // Seek with 0 and SEEK_CUR does not modify anything despite the const_cast, // so it's safe to do this. diff --git a/Ladybird/RequestManagerQt.h b/Ladybird/RequestManagerQt.h index 5789e8a0caa..eb8b7365c0e 100644 --- a/Ladybird/RequestManagerQt.h +++ b/Ladybird/RequestManagerQt.h @@ -44,7 +44,7 @@ private: virtual void set_should_buffer_all_input(bool) override { } virtual bool stop() override { return false; } - virtual void stream_into(Core::Stream::Stream&) override { } + virtual void stream_into(AK::Stream&) override { } void did_finish(); diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index 23f7f340aaa..db37dfcd265 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -338,7 +338,7 @@ public:)~~~"); static i32 static_message_id() { return (int)MessageID::@message.pascal_name@; } virtual const char* message_name() const override { return "@endpoint.name@::@message.pascal_name@"; } - static ErrorOr> decode(Core::Stream::Stream& stream, Core::Stream::LocalSocket& socket) + static ErrorOr> decode(AK::Stream& stream, Core::Stream::LocalSocket& socket) { IPC::Decoder decoder { stream, socket };)~~~"); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp index f79b2bb8895..8d7435486e7 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp @@ -450,7 +450,7 @@ static ErrorOr parse_name_aliases(Core::Stream::BufferedFile& file, Unicod static ErrorOr parse_value_alias_list(Core::Stream::BufferedFile& file, StringView desired_category, Vector const& value_list, Vector& 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 buffer; auto append_alias = [&](auto alias, auto value) { @@ -646,7 +646,7 @@ static ErrorOr parse_block_display_names(Core::Stream::BufferedFile& file, 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 {}; } diff --git a/Meta/Lagom/Wasm/js_repl.cpp b/Meta/Lagom/Wasm/js_repl.cpp index 60197e237b6..b40a9732260 100644 --- a/Meta/Lagom/Wasm/js_repl.cpp +++ b/Meta/Lagom/Wasm/js_repl.cpp @@ -63,7 +63,7 @@ void displayln(CheckedFormatString format_string, Args const&... args) void displayln() { user_display("\n", 1); } -class UserDisplayStream final : public Core::Stream::Stream { +class UserDisplayStream final : public AK::Stream { virtual ErrorOr read(Bytes) override { return Error::from_string_view("Not readable"sv); }; virtual ErrorOr write(ReadonlyBytes bytes) override { diff --git a/Tests/LibCore/TestLibCoreIODevice.cpp b/Tests/LibCore/TestLibCoreIODevice.cpp index ae37acabb15..4c4352fbeab 100644 --- a/Tests/LibCore/TestLibCoreIODevice.cpp +++ b/Tests/LibCore/TestLibCoreIODevice.cpp @@ -53,19 +53,19 @@ TEST_CASE(file_get_read_position) } off_t offset = 0; - VERIFY(file->seek(0, Core::SeekMode::FromCurrentPosition, &offset)); + VERIFY(file->seek(0, SeekMode::FromCurrentPosition, &offset)); EXPECT_EQ(offset, static_cast(i + step_size)); } { off_t offset = 0; - VERIFY(file->seek(0, Core::SeekMode::FromEndPosition, &offset)); + VERIFY(file->seek(0, SeekMode::FromEndPosition, &offset)); EXPECT_EQ(offset, 10240); } { off_t offset = 0; - VERIFY(file->seek(0, Core::SeekMode::SetPosition, &offset)); + VERIFY(file->seek(0, SeekMode::SetPosition, &offset)); EXPECT_EQ(offset, 0); } } diff --git a/Tests/LibCore/TestLibCoreStream.cpp b/Tests/LibCore/TestLibCoreStream.cpp index 2200293b10b..0549a355183 100644 --- a/Tests/LibCore/TestLibCoreStream.cpp +++ b/Tests/LibCore/TestLibCoreStream.cpp @@ -89,17 +89,17 @@ TEST_CASE(file_seeking_around) 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(!file->read_entire_buffer(buffer).is_error()); 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(!file->read_entire_buffer(buffer).is_error()); 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(!file->read_entire_buffer(buffer).is_error()); EXPECT_EQ(buffer_contents, expected_seek_contents3); @@ -122,7 +122,7 @@ TEST_CASE(file_adopt_fd) 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(!file->read_entire_buffer(buffer).is_error()); 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 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()); auto maybe_line = file->read_line(buffer); EXPECT(!maybe_line.is_error()); EXPECT_EQ(maybe_line.value().length(), 4095ul); // 4095 bytes on the third line // 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); EXPECT(!maybe_after_seek_line.is_error()); 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. { - 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); } @@ -513,7 +513,7 @@ TEST_CASE(buffered_file_tell_and_seek) // 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); } @@ -527,7 +527,7 @@ TEST_CASE(buffered_file_tell_and_seek) // 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); } @@ -541,7 +541,7 @@ TEST_CASE(buffered_file_tell_and_seek) // 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); } @@ -697,7 +697,7 @@ TEST_CASE(allocating_memory_stream_10kb) 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. 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, // so testing with sizes that will not trigger a write will yield unexpected results. - auto bit_write_stream = MUST(Core::Stream::LittleEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); - auto bit_read_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(MaybeOwned(*memory_stream))); + auto bit_write_stream = MUST(Core::Stream::LittleEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); + auto bit_read_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(MaybeOwned(*memory_stream))); // 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, // so testing with sizes that will not trigger a write will yield unexpected results. - auto bit_write_stream = MUST(Core::Stream::BigEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); - auto bit_read_stream = MUST(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); + auto bit_write_stream = MUST(Core::Stream::BigEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); + auto bit_read_stream = MUST(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits. { diff --git a/Userland/Applets/ResourceGraph/main.cpp b/Userland/Applets/ResourceGraph/main.cpp index 481ec73d487..8ba289d9370 100644 --- a/Userland/Applets/ResourceGraph/main.cpp +++ b/Userland/Applets/ResourceGraph/main.cpp @@ -148,7 +148,7 @@ private: { if (file) { // Seeking to the beginning causes a data refresh! - TRY(file->seek(0, Core::Stream::SeekMode::SetPosition)); + TRY(file->seek(0, SeekMode::SetPosition)); } else { file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read)); } diff --git a/Userland/Applications/HexEditor/HexDocument.cpp b/Userland/Applications/HexEditor/HexDocument.cpp index 7b42026f384..140cd1193bb 100644 --- a/Userland/Applications/HexEditor/HexDocument.cpp +++ b/Userland/Applications/HexEditor/HexDocument.cpp @@ -64,7 +64,7 @@ bool HexDocumentMemory::write_to_file(NonnullRefPtr file) if (!file->write(m_buffer.data(), m_buffer.size())) return false; for (auto& change : m_changes) { - file->seek(change.key, Core::SeekMode::SetPosition); + file->seek(change.key, SeekMode::SetPosition); file->write(&change.value, 1); } return true; @@ -79,7 +79,7 @@ HexDocumentFile::HexDocumentFile(NonnullRefPtr file) void HexDocumentFile::write_to_file() { 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); } clear_changes(); @@ -105,7 +105,7 @@ bool HexDocumentFile::write_to_file(NonnullRefPtr file) } for (auto& change : m_changes) { - file->seek(change.key, Core::SeekMode::SetPosition); + file->seek(change.key, SeekMode::SetPosition); file->write(&change.value, 1); } @@ -149,12 +149,12 @@ void HexDocumentFile::set_file(NonnullRefPtr file) m_file = file; off_t size = 0; - if (!file->seek(0, Core::SeekMode::FromEndPosition, &size)) { + if (!file->seek(0, SeekMode::FromEndPosition, &size)) { m_file_size = 0; } else { m_file_size = size; } - file->seek(0, Core::SeekMode::SetPosition); + file->seek(0, SeekMode::SetPosition); clear_changes(); // make sure the next get operation triggers a read @@ -169,7 +169,7 @@ NonnullRefPtr HexDocumentFile::file() const void HexDocumentFile::ensure_position_in_buffer(size_t position) { 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_buffer_file_pos = position; } diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 8fbd4c38bf0..a9af2c36ac9 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -172,7 +172,7 @@ RefPtr Image::copy_bitmap(Selection const& selection) const return cropped_bitmap_or_error.release_value_but_fixme_should_propagate_errors(); } -ErrorOr Image::export_bmp_to_file(NonnullOwnPtr stream, bool preserve_alpha_channel) const +ErrorOr Image::export_bmp_to_file(NonnullOwnPtr stream, bool preserve_alpha_channel) const { auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; auto bitmap = TRY(compose_bitmap(bitmap_format)); @@ -183,7 +183,7 @@ ErrorOr Image::export_bmp_to_file(NonnullOwnPtr stre return {}; } -ErrorOr Image::export_png_to_file(NonnullOwnPtr stream, bool preserve_alpha_channel) const +ErrorOr Image::export_png_to_file(NonnullOwnPtr stream, bool preserve_alpha_channel) const { auto bitmap_format = preserve_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; auto bitmap = TRY(compose_bitmap(bitmap_format)); @@ -193,7 +193,7 @@ ErrorOr Image::export_png_to_file(NonnullOwnPtr stre return {}; } -ErrorOr Image::export_qoi_to_file(NonnullOwnPtr stream) const +ErrorOr Image::export_qoi_to_file(NonnullOwnPtr stream) const { auto bitmap = TRY(compose_bitmap(Gfx::BitmapFormat::BGRA8888)); diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h index b78dde7372b..ed343144257 100644 --- a/Userland/Applications/PixelPaint/Image.h +++ b/Userland/Applications/PixelPaint/Image.h @@ -72,9 +72,9 @@ public: void paint_into(GUI::Painter&, Gfx::IntRect const& dest_rect) const; ErrorOr serialize_as_json(JsonObjectSerializer& json) const; - ErrorOr export_bmp_to_file(NonnullOwnPtr, bool preserve_alpha_channel) const; - ErrorOr export_png_to_file(NonnullOwnPtr, bool preserve_alpha_channel) const; - ErrorOr export_qoi_to_file(NonnullOwnPtr) const; + ErrorOr export_bmp_to_file(NonnullOwnPtr, bool preserve_alpha_channel) const; + ErrorOr export_png_to_file(NonnullOwnPtr, bool preserve_alpha_channel) const; + ErrorOr export_qoi_to_file(NonnullOwnPtr) const; void move_layer_to_front(Layer&); void move_layer_to_back(Layer&); diff --git a/Userland/Applications/Spreadsheet/ExportDialog.cpp b/Userland/Applications/Spreadsheet/ExportDialog.cpp index 9be6f8d91ed..1e81e094ec0 100644 --- a/Userland/Applications/Spreadsheet/ExportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ExportDialog.cpp @@ -88,7 +88,7 @@ CSVExportDialogPage::CSVExportDialogPage(Sheet const& sheet) update_preview(); } -auto CSVExportDialogPage::generate(Core::Stream::Stream& stream, GenerationType type) -> ErrorOr +auto CSVExportDialogPage::generate(AK::Stream& stream, GenerationType type) -> ErrorOr { auto delimiter = TRY([this]() -> ErrorOr { if (m_delimiter_other_radio->is_checked()) { diff --git a/Userland/Applications/Spreadsheet/ExportDialog.h b/Userland/Applications/Spreadsheet/ExportDialog.h index 6890da315eb..3579e135aa6 100644 --- a/Userland/Applications/Spreadsheet/ExportDialog.h +++ b/Userland/Applications/Spreadsheet/ExportDialog.h @@ -27,7 +27,7 @@ struct CSVExportDialogPage { Preview }; - ErrorOr generate(Core::Stream::Stream&, GenerationType); + ErrorOr generate(AK::Stream&, GenerationType); protected: void update_preview(); diff --git a/Userland/Applications/Spreadsheet/Writers/CSV.h b/Userland/Applications/Spreadsheet/Writers/CSV.h index fb0cbd4ca7e..e8e07341d32 100644 --- a/Userland/Applications/Spreadsheet/Writers/CSV.h +++ b/Userland/Applications/Spreadsheet/Writers/CSV.h @@ -15,13 +15,13 @@ namespace Writer { class CSV { public: template - static ErrorOr generate(Core::Stream::Stream& output, ContainerType const& data, Vector headers = {}, WriterBehavior behaviors = default_behaviors()) + static ErrorOr generate(AK::Stream& output, ContainerType const& data, Vector headers = {}, WriterBehavior behaviors = default_behaviors()) { return XSV::generate(output, data, { ",", "\"", WriterTraits::Repeat }, move(headers), behaviors); } template - static ErrorOr generate_preview(Core::Stream::Stream& output, ContainerType const& data, Vector headers = {}, WriterBehavior behaviors = default_behaviors()) + static ErrorOr generate_preview(AK::Stream& output, ContainerType const& data, Vector headers = {}, WriterBehavior behaviors = default_behaviors()) { return XSV::generate_preview(output, data, { ",", "\"", WriterTraits::Repeat }, move(headers), behaviors); } diff --git a/Userland/Applications/Spreadsheet/Writers/XSV.h b/Userland/Applications/Spreadsheet/Writers/XSV.h index f81a17d4edb..818e3d3c1c9 100644 --- a/Userland/Applications/Spreadsheet/Writers/XSV.h +++ b/Userland/Applications/Spreadsheet/Writers/XSV.h @@ -42,7 +42,7 @@ constexpr WriterBehavior default_behaviors() template> class XSV { public: - static ErrorOr generate(Core::Stream::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) + static ErrorOr generate(AK::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) { auto writer = XSV(output, data, traits, headers, behaviors); auto with_headers = has_flag(writer.m_behaviors, WriterBehavior::WriteHeaders); @@ -63,7 +63,7 @@ public: return {}; } - static ErrorOr generate_preview(Core::Stream::Stream& output, ContainerType const& data, WriterTraits traits, HeaderType headers = {}, WriterBehavior behaviors = default_behaviors()) + static ErrorOr 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 lines_written = 0; @@ -93,7 +93,7 @@ public: } 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_traits(move(traits)) , m_behaviors(behaviors) @@ -170,7 +170,7 @@ private: WriterTraits m_traits; WriterBehavior m_behaviors; HeaderType m_names; - Core::Stream::Stream& m_output; + AK::Stream& m_output; }; } diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.cpp b/Userland/DevTools/UserspaceEmulator/Emulator.cpp index a0946215507..2034d456b2a 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator.cpp @@ -500,7 +500,7 @@ void Emulator::dump_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()) 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(); } -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; timeval tv {}; diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.h b/Userland/DevTools/UserspaceEmulator/Emulator.h index 4bb731a70e5..8675911b194 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.h +++ b/Userland/DevTools/UserspaceEmulator/Emulator.h @@ -32,7 +32,7 @@ public: Emulator(DeprecatedString const& executable_path, Vector const& arguments, Vector const& environment); - void set_profiling_details(bool should_dump_profile, size_t instruction_interval, Core::Stream::Stream* profile_stream, NonnullOwnPtrVector* profiler_strings, Vector* profiler_string_id_map) + void set_profiling_details(bool should_dump_profile, size_t instruction_interval, AK::Stream* profile_stream, NonnullOwnPtrVector* profiler_strings, Vector* profiler_string_id_map) { m_is_profiling = should_dump_profile; m_profile_instruction_interval = instruction_interval; @@ -46,7 +46,7 @@ public: 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& profiler_strings() { return *m_profiler_strings; } Vector& profiler_string_id_map() { return *m_profiler_string_id_map; } @@ -139,8 +139,8 @@ private: void send_signal(int); - void emit_profile_sample(Core::Stream::Stream&); - void emit_profile_event(Core::Stream::Stream&, StringView event_name, DeprecatedString const& contents); + void emit_profile_sample(AK::Stream&); + void emit_profile_event(AK::Stream&, StringView event_name, DeprecatedString const& contents); int virt$accept4(FlatPtr); u32 virt$allocate_tls(FlatPtr, size_t); @@ -295,7 +295,7 @@ private: RangeAllocator m_range_allocator; - Core::Stream::Stream* m_profile_stream { nullptr }; + AK::Stream* m_profile_stream { nullptr }; Vector* m_profiler_string_id_map { nullptr }; NonnullOwnPtrVector* m_profiler_strings { nullptr }; diff --git a/Userland/DevTools/UserspaceEmulator/main.cpp b/Userland/DevTools/UserspaceEmulator/main.cpp index df7d0ee1d54..336cc192e0f 100644 --- a/Userland/DevTools/UserspaceEmulator/main.cpp +++ b/Userland/DevTools/UserspaceEmulator/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv, char** env) if (dump_profile && profile_dump_path.is_empty()) profile_dump_path = DeprecatedString::formatted("{}.{}.profile", LexicalPath(executable_path).basename(), getpid()); - OwnPtr profile_stream; + OwnPtr profile_stream; OwnPtr> profile_strings; OwnPtr> profile_string_id_map; diff --git a/Userland/Libraries/LibArchive/TarStream.cpp b/Userland/Libraries/LibArchive/TarStream.cpp index 218520305e0..19f1f6fb6fa 100644 --- a/Userland/Libraries/LibArchive/TarStream.cpp +++ b/Userland/Libraries/LibArchive/TarStream.cpp @@ -51,7 +51,7 @@ ErrorOr TarFileStream::write(ReadonlyBytes) return Error::from_errno(EBADF); } -ErrorOr> TarInputStream::construct(NonnullOwnPtr stream) +ErrorOr> TarInputStream::construct(NonnullOwnPtr stream) { auto tar_stream = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TarInputStream(move(stream)))); @@ -60,7 +60,7 @@ ErrorOr> TarInputStream::construct(NonnullOwnPtr stream) +TarInputStream::TarInputStream(NonnullOwnPtr stream) : m_stream(move(stream)) { } @@ -136,7 +136,7 @@ TarFileStream TarInputStream::file_contents() return TarFileStream(*this); } -TarOutputStream::TarOutputStream(MaybeOwned stream) +TarOutputStream::TarOutputStream(MaybeOwned stream) : m_stream(move(stream)) { } diff --git a/Userland/Libraries/LibArchive/TarStream.h b/Userland/Libraries/LibArchive/TarStream.h index f585d26ca1e..87ef75d21c4 100644 --- a/Userland/Libraries/LibArchive/TarStream.h +++ b/Userland/Libraries/LibArchive/TarStream.h @@ -16,7 +16,7 @@ namespace Archive { class TarInputStream; -class TarFileStream : public Core::Stream::Stream { +class TarFileStream : public AK::Stream { public: virtual ErrorOr read(Bytes) override; virtual ErrorOr write(ReadonlyBytes) override; @@ -34,7 +34,7 @@ private: class TarInputStream { public: - static ErrorOr> construct(NonnullOwnPtr); + static ErrorOr> construct(NonnullOwnPtr); ErrorOr advance(); bool finished() const { return m_found_end_of_archive || m_stream->is_eof(); } ErrorOr valid() const; @@ -45,11 +45,11 @@ public: ErrorOr for_each_extended_header(F func); private: - TarInputStream(NonnullOwnPtr); + TarInputStream(NonnullOwnPtr); ErrorOr load_next_header(); TarFileHeader m_header; - NonnullOwnPtr m_stream; + NonnullOwnPtr m_stream; unsigned long m_file_offset { 0 }; int m_generation { 0 }; bool m_found_end_of_archive { false }; @@ -59,14 +59,14 @@ private: class TarOutputStream { public: - TarOutputStream(MaybeOwned); + TarOutputStream(MaybeOwned); ErrorOr add_file(StringView path, mode_t, ReadonlyBytes); ErrorOr add_link(StringView path, mode_t, StringView); ErrorOr add_directory(StringView path, mode_t); ErrorOr finish(); private: - MaybeOwned m_stream; + MaybeOwned m_stream; bool m_finished { false }; friend class TarFileStream; diff --git a/Userland/Libraries/LibArchive/Zip.cpp b/Userland/Libraries/LibArchive/Zip.cpp index 366f50338c7..27c9a537076 100644 --- a/Userland/Libraries/LibArchive/Zip.cpp +++ b/Userland/Libraries/LibArchive/Zip.cpp @@ -100,7 +100,7 @@ ErrorOr Zip::for_each_member(Function return true; } -ZipOutputStream::ZipOutputStream(NonnullOwnPtr stream) +ZipOutputStream::ZipOutputStream(NonnullOwnPtr stream) : m_stream(move(stream)) { } diff --git a/Userland/Libraries/LibArchive/Zip.h b/Userland/Libraries/LibArchive/Zip.h index a4cec32048a..ad3c3bc7580 100644 --- a/Userland/Libraries/LibArchive/Zip.h +++ b/Userland/Libraries/LibArchive/Zip.h @@ -55,7 +55,7 @@ struct [[gnu::packed]] EndOfCentralDirectory { return true; } - ErrorOr write(Core::Stream::Stream& stream) const + ErrorOr write(AK::Stream& stream) const { auto write_value = [&stream](auto value) { return stream.write_entire_buffer({ &value, sizeof(value) }); @@ -141,7 +141,7 @@ struct [[gnu::packed]] CentralDirectoryRecord { return true; } - ErrorOr write(Core::Stream::Stream& stream) const + ErrorOr write(AK::Stream& stream) const { auto write_value = [&stream](auto value) { return stream.write_entire_buffer({ &value, sizeof(value) }); @@ -210,7 +210,7 @@ struct [[gnu::packed]] LocalFileHeader { return true; } - ErrorOr write(Core::Stream::Stream& stream) const + ErrorOr write(AK::Stream& stream) const { auto write_value = [&stream](auto value) { return stream.write_entire_buffer({ &value, sizeof(value) }); @@ -267,13 +267,13 @@ private: class ZipOutputStream { public: - ZipOutputStream(NonnullOwnPtr); + ZipOutputStream(NonnullOwnPtr); ErrorOr add_member(ZipMember const&); ErrorOr finish(); private: - NonnullOwnPtr m_stream; + NonnullOwnPtr m_stream; Vector m_members; bool m_finished { false }; diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index 8a7c9faa175..6bae382a54d 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -25,7 +25,7 @@ namespace Audio { -FlacLoaderPlugin::FlacLoaderPlugin(NonnullOwnPtr stream) +FlacLoaderPlugin::FlacLoaderPlugin(NonnullOwnPtr stream) : LoaderPlugin(move(stream)) { } @@ -60,7 +60,7 @@ MaybeLoaderError FlacLoaderPlugin::initialize() // 11.5 STREAM MaybeLoaderError FlacLoaderPlugin::parse_header() { - auto bit_input = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); + auto bit_input = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); // A mixture of VERIFY and the non-crashing TRY(). #define FLAC_VERIFY(check, category, msg) \ @@ -79,7 +79,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() auto streaminfo = TRY(next_meta_block(*bit_input)); 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 = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*streaminfo_data_memory))); + auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*streaminfo_data_memory))); // 11.10 METADATA_BLOCK_STREAMINFO m_min_block_size = LOADER_TRY(streaminfo_data->read_bits(16)); @@ -150,7 +150,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) { auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); - auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); + auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); 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)); // Note: We are seeking before reading the value to ensure that we stayed inside buffer's size. 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 }; auto const description_string_length = LOADER_TRY(picture_block_bytes->read_bits(32)); 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 { Span { reinterpret_cast(block.data.bytes().data() + offset_before_seeking), (size_t)description_string_length } }; 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)); 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 { Span { block.data.bytes().data() + offset_before_seeking, (size_t)picture_size } }; m_pictures.append(move(picture)); @@ -187,7 +187,7 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block) { auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); - auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); + auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); for (size_t i = 0; i < block.length / 18; ++i) { // 11.14. SEEKPOINT FlacSeekPoint seekpoint { @@ -259,7 +259,7 @@ MaybeLoaderError FlacLoaderPlugin::seek(int int_sample_index) // No seektable or no fitting entry: Perform normal forward read if (!maybe_target_seekpoint.has_value()) { 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; } 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); auto position = target_seekpoint.byte_offset + m_data_start_location; - if (m_stream->seek(static_cast(position), Core::Stream::SeekMode::SetPosition).is_error()) + if (m_stream->seek(static_cast(position), SeekMode::SetPosition).is_error()) 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; @@ -333,7 +333,7 @@ MaybeLoaderError FlacLoaderPlugin::next_frame(Span target_vector) } \ } while (0) - auto bit_stream = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); + auto bit_stream = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); // TODO: Check the CRC-16 checksum (and others) by keeping track of read data diff --git a/Userland/Libraries/LibAudio/FlacLoader.h b/Userland/Libraries/LibAudio/FlacLoader.h index 7aba887b2ab..cfc91701341 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.h +++ b/Userland/Libraries/LibAudio/FlacLoader.h @@ -47,7 +47,7 @@ ALWAYS_INLINE ErrorOr 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) class FlacLoaderPlugin : public LoaderPlugin { public: - explicit FlacLoaderPlugin(NonnullOwnPtr stream); + explicit FlacLoaderPlugin(NonnullOwnPtr stream); virtual ~FlacLoaderPlugin() override = default; static Result, LoaderError> create(StringView path); diff --git a/Userland/Libraries/LibAudio/Loader.cpp b/Userland/Libraries/LibAudio/Loader.cpp index 8f0065123b4..12a52795193 100644 --- a/Userland/Libraries/LibAudio/Loader.cpp +++ b/Userland/Libraries/LibAudio/Loader.cpp @@ -11,7 +11,7 @@ namespace Audio { -LoaderPlugin::LoaderPlugin(NonnullOwnPtr stream) +LoaderPlugin::LoaderPlugin(NonnullOwnPtr stream) : m_stream(move(stream)) { } diff --git a/Userland/Libraries/LibAudio/Loader.h b/Userland/Libraries/LibAudio/Loader.h index 08ba0e6f5b1..ff05d346586 100644 --- a/Userland/Libraries/LibAudio/Loader.h +++ b/Userland/Libraries/LibAudio/Loader.h @@ -30,7 +30,7 @@ using MaybeLoaderError = Result; class LoaderPlugin { public: - explicit LoaderPlugin(NonnullOwnPtr stream); + explicit LoaderPlugin(NonnullOwnPtr stream); virtual ~LoaderPlugin() = default; virtual LoaderSamples get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) = 0; @@ -58,7 +58,7 @@ public: Vector const& pictures() const { return m_pictures; }; protected: - NonnullOwnPtr m_stream; + NonnullOwnPtr m_stream; Vector m_pictures; }; diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp index 15c14eae336..59eb0dff0d2 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.cpp +++ b/Userland/Libraries/LibAudio/MP3Loader.cpp @@ -14,7 +14,7 @@ namespace Audio { DSP::MDCT<12> MP3LoaderPlugin::s_mdct_12; DSP::MDCT<36> MP3LoaderPlugin::s_mdct_36; -MP3LoaderPlugin::MP3LoaderPlugin(NonnullOwnPtr stream) +MP3LoaderPlugin::MP3LoaderPlugin(NonnullOwnPtr stream) : LoaderPlugin(move(stream)) { } @@ -41,7 +41,7 @@ Result, LoaderError> MP3LoaderPlugin::create(Byte MaybeLoaderError MP3LoaderPlugin::initialize() { - m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); + m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); TRY(synchronize()); @@ -55,7 +55,7 @@ MaybeLoaderError MP3LoaderPlugin::initialize() TRY(build_seek_table()); - LOADER_TRY(m_stream->seek(0, Core::Stream::SeekMode::SetPosition)); + LOADER_TRY(m_stream->seek(0, SeekMode::SetPosition)); return {}; } @@ -76,7 +76,7 @@ MaybeLoaderError MP3LoaderPlugin::seek(int const position) { for (auto const& seek_entry : m_seek_table) { 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>(); break; } @@ -140,7 +140,7 @@ MaybeLoaderError MP3LoaderPlugin::build_seek_table() m_bitstream->align_to_byte_boundary(); 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(); 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) 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. // Bitstream should have a method to sync its state to the underlying stream. @@ -242,7 +242,7 @@ ErrorOr MP3LoaderPlugin::read_frame_data(MP3::Header TRY(m_bit_reservoir.discard(old_reservoir_size - frame.main_data_begin)); - auto reservoir_stream = TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(m_bit_reservoir))); + auto reservoir_stream = TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(m_bit_reservoir))); for (size_t granule_index = 0; granule_index < 2; granule_index++) { for (size_t channel_index = 0; channel_index < header.channel_count(); channel_index++) { diff --git a/Userland/Libraries/LibAudio/MP3Loader.h b/Userland/Libraries/LibAudio/MP3Loader.h index de00366087f..48d5ab1440c 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.h +++ b/Userland/Libraries/LibAudio/MP3Loader.h @@ -22,7 +22,7 @@ struct ScaleFactorBand; class MP3LoaderPlugin : public LoaderPlugin { public: - explicit MP3LoaderPlugin(NonnullOwnPtr stream); + explicit MP3LoaderPlugin(NonnullOwnPtr stream); virtual ~MP3LoaderPlugin() = default; static Result, LoaderError> create(StringView path); diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp index d96f2f26336..91e96887618 100644 --- a/Userland/Libraries/LibAudio/WavLoader.cpp +++ b/Userland/Libraries/LibAudio/WavLoader.cpp @@ -18,7 +18,7 @@ namespace Audio { static constexpr size_t const maximum_wav_size = 1 * GiB; // FIXME: is there a more appropriate size limit? -WavLoaderPlugin::WavLoaderPlugin(NonnullOwnPtr stream) +WavLoaderPlugin::WavLoaderPlugin(NonnullOwnPtr stream) : LoaderPlugin(move(stream)) { } @@ -51,7 +51,7 @@ MaybeLoaderError WavLoaderPlugin::initialize() } template -MaybeLoaderError WavLoaderPlugin::read_samples_from_stream(Core::Stream::Stream& stream, SampleReader read_sample, FixedArray& samples) const +MaybeLoaderError WavLoaderPlugin::read_samples_from_stream(AK::Stream& stream, SampleReader read_sample, FixedArray& samples) const { switch (m_num_channels) { 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. -static ErrorOr read_sample_int24(Core::Stream::Stream& stream) +static ErrorOr read_sample_int24(AK::Stream& stream) { u8 byte = 0; TRY(stream.read(Bytes { &byte, 1 })); @@ -93,7 +93,7 @@ static ErrorOr read_sample_int24(Core::Stream::Stream& stream) } template -static ErrorOr read_sample(Core::Stream::Stream& stream) +static ErrorOr read_sample(AK::Stream& stream) { T sample { 0 }; 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(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; return {}; diff --git a/Userland/Libraries/LibAudio/WavLoader.h b/Userland/Libraries/LibAudio/WavLoader.h index c8f3b44904c..28be15af862 100644 --- a/Userland/Libraries/LibAudio/WavLoader.h +++ b/Userland/Libraries/LibAudio/WavLoader.h @@ -29,7 +29,7 @@ static constexpr unsigned const WAVE_FORMAT_EXTENSIBLE = 0xFFFE; // Determined b // Parses and reads audio data from a WAV file. class WavLoaderPlugin : public LoaderPlugin { public: - explicit WavLoaderPlugin(NonnullOwnPtr stream); + explicit WavLoaderPlugin(NonnullOwnPtr stream); static Result, LoaderError> create(StringView path); static Result, LoaderError> create(Bytes buffer); @@ -55,7 +55,7 @@ private: LoaderSamples samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const; template - MaybeLoaderError read_samples_from_stream(Core::Stream::Stream& stream, SampleReader read_sample, FixedArray& samples) const; + MaybeLoaderError read_samples_from_stream(AK::Stream& stream, SampleReader read_sample, FixedArray& samples) const; u32 m_sample_rate { 0 }; u16 m_num_channels { 0 }; diff --git a/Userland/Libraries/LibCompress/Brotli.h b/Userland/Libraries/LibCompress/Brotli.h index 879a66a3e61..ee8fa7fa11d 100644 --- a/Userland/Libraries/LibCompress/Brotli.h +++ b/Userland/Libraries/LibCompress/Brotli.h @@ -13,8 +13,8 @@ namespace Compress { +using AK::Stream; using Core::Stream::LittleEndianInputBitStream; -using Core::Stream::Stream; class BrotliDecompressionStream : public Stream { public: diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index f6afe0eb567..48bbd41c599 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -188,13 +188,13 @@ ErrorOr DeflateDecompressor::UncompressedBlock::try_read_more() return true; } -ErrorOr> DeflateDecompressor::construct(MaybeOwned stream) +ErrorOr> DeflateDecompressor::construct(MaybeOwned stream) { auto output_buffer = TRY(CircularBuffer::create_empty(32 * KiB)); return TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateDecompressor(move(stream), move(output_buffer)))); } -DeflateDecompressor::DeflateDecompressor(MaybeOwned stream, CircularBuffer output_buffer) +DeflateDecompressor::DeflateDecompressor(MaybeOwned stream, CircularBuffer output_buffer) : m_input_stream(make(move(stream))) , m_output_buffer(move(output_buffer)) { @@ -446,7 +446,7 @@ ErrorOr DeflateDecompressor::decode_codes(CanonicalCode& literal_code, Opt return {}; } -ErrorOr> DeflateCompressor::construct(MaybeOwned stream, CompressionLevel compression_level) +ErrorOr> DeflateCompressor::construct(MaybeOwned stream, CompressionLevel compression_level) { 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))); @@ -1017,7 +1017,7 @@ ErrorOr DeflateCompressor::final_flush() ErrorOr DeflateCompressor::compress_all(ReadonlyBytes bytes, CompressionLevel compression_level) { auto output_stream = TRY(try_make()); - auto deflate_stream = TRY(DeflateCompressor::construct(MaybeOwned(*output_stream), compression_level)); + auto deflate_stream = TRY(DeflateCompressor::construct(MaybeOwned(*output_stream), compression_level)); TRY(deflate_stream->write_entire_buffer(bytes)); TRY(deflate_stream->final_flush()); diff --git a/Userland/Libraries/LibCompress/Deflate.h b/Userland/Libraries/LibCompress/Deflate.h index 6268996c58e..a709e00a6a2 100644 --- a/Userland/Libraries/LibCompress/Deflate.h +++ b/Userland/Libraries/LibCompress/Deflate.h @@ -37,7 +37,7 @@ private: Array m_bit_code_lengths {}; }; -class DeflateDecompressor final : public Core::Stream::Stream { +class DeflateDecompressor final : public AK::Stream { private: class CompressedBlock { public: @@ -74,7 +74,7 @@ public: friend CompressedBlock; friend UncompressedBlock; - static ErrorOr> construct(MaybeOwned stream); + static ErrorOr> construct(MaybeOwned stream); ~DeflateDecompressor(); virtual ErrorOr read(Bytes) override; @@ -86,7 +86,7 @@ public: static ErrorOr decompress_all(ReadonlyBytes); private: - DeflateDecompressor(MaybeOwned stream, CircularBuffer buffer); + DeflateDecompressor(MaybeOwned stream, CircularBuffer buffer); ErrorOr decode_length(u32); ErrorOr decode_distance(u32); @@ -104,7 +104,7 @@ private: CircularBuffer m_output_buffer; }; -class DeflateCompressor final : public Core::Stream::Stream { +class DeflateCompressor final : public AK::Stream { public: 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; @@ -139,7 +139,7 @@ public: BEST // WARNING: this one can take an unreasonable amount of time! }; - static ErrorOr> construct(MaybeOwned, CompressionLevel = CompressionLevel::GOOD); + static ErrorOr> construct(MaybeOwned, CompressionLevel = CompressionLevel::GOOD); ~DeflateCompressor(); virtual ErrorOr read(Bytes) override; diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp index 0b702f28b7b..f47b6e2083c 100644 --- a/Userland/Libraries/LibCompress/Gzip.cpp +++ b/Userland/Libraries/LibCompress/Gzip.cpp @@ -38,9 +38,9 @@ bool BlockHeader::supported_by_implementation() const return true; } -ErrorOr> GzipDecompressor::Member::construct(BlockHeader header, Core::Stream::Stream& stream) +ErrorOr> GzipDecompressor::Member::construct(BlockHeader header, AK::Stream& stream) { - auto deflate_stream = TRY(DeflateDecompressor::construct(MaybeOwned(stream))); + auto deflate_stream = TRY(DeflateDecompressor::construct(MaybeOwned(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 stream) +GzipDecompressor::GzipDecompressor(NonnullOwnPtr stream) : m_input_stream(move(stream)) { } @@ -186,7 +186,7 @@ ErrorOr GzipDecompressor::write(ReadonlyBytes) return Error::from_errno(EBADF); } -GzipCompressor::GzipCompressor(MaybeOwned stream) +GzipCompressor::GzipCompressor(MaybeOwned stream) : m_output_stream(move(stream)) { } @@ -236,7 +236,7 @@ void GzipCompressor::close() ErrorOr GzipCompressor::compress_all(ReadonlyBytes bytes) { auto output_stream = TRY(try_make()); - GzipCompressor gzip_stream { MaybeOwned(*output_stream) }; + GzipCompressor gzip_stream { MaybeOwned(*output_stream) }; TRY(gzip_stream.write_entire_buffer(bytes)); diff --git a/Userland/Libraries/LibCompress/Gzip.h b/Userland/Libraries/LibCompress/Gzip.h index ddda776f5e5..990e78304e9 100644 --- a/Userland/Libraries/LibCompress/Gzip.h +++ b/Userland/Libraries/LibCompress/Gzip.h @@ -38,9 +38,9 @@ struct Flags { static constexpr u8 MAX = FTEXT | FHCRC | FEXTRA | FNAME | FCOMMENT; }; -class GzipDecompressor final : public Core::Stream::Stream { +class GzipDecompressor final : public AK::Stream { public: - GzipDecompressor(NonnullOwnPtr); + GzipDecompressor(NonnullOwnPtr); ~GzipDecompressor(); virtual ErrorOr read(Bytes) override; @@ -56,7 +56,7 @@ public: private: class Member { public: - static ErrorOr> construct(BlockHeader header, Core::Stream::Stream&); + static ErrorOr> construct(BlockHeader header, AK::Stream&); BlockHeader m_header; NonnullOwnPtr m_stream; @@ -70,7 +70,7 @@ private: Member const& current_member() const { return *m_current_member; } Member& current_member() { return *m_current_member; } - NonnullOwnPtr m_input_stream; + NonnullOwnPtr m_input_stream; u8 m_partial_header[sizeof(BlockHeader)]; size_t m_partial_header_offset { 0 }; OwnPtr m_current_member {}; @@ -78,9 +78,9 @@ private: bool m_eof { false }; }; -class GzipCompressor final : public Core::Stream::Stream { +class GzipCompressor final : public AK::Stream { public: - GzipCompressor(MaybeOwned); + GzipCompressor(MaybeOwned); virtual ErrorOr read(Bytes) override; virtual ErrorOr write(ReadonlyBytes) override; @@ -91,7 +91,7 @@ public: static ErrorOr compress_all(ReadonlyBytes bytes); private: - MaybeOwned m_output_stream; + MaybeOwned m_output_stream; }; } diff --git a/Userland/Libraries/LibCompress/Zlib.cpp b/Userland/Libraries/LibCompress/Zlib.cpp index ff2d78aa9c1..feab384f44e 100644 --- a/Userland/Libraries/LibCompress/Zlib.cpp +++ b/Userland/Libraries/LibCompress/Zlib.cpp @@ -69,7 +69,7 @@ u32 ZlibDecompressor::checksum() return m_checksum; } -ErrorOr> ZlibCompressor::construct(MaybeOwned stream, ZlibCompressionLevel compression_level) +ErrorOr> ZlibCompressor::construct(MaybeOwned stream, ZlibCompressionLevel compression_level) { // Zlib only defines Deflate as a compression method. auto compression_method = ZlibCompressionMethod::Deflate; @@ -83,7 +83,7 @@ ErrorOr> ZlibCompressor::construct(MaybeOwned stream, NonnullOwnPtr compressor_stream) +ZlibCompressor::ZlibCompressor(MaybeOwned stream, NonnullOwnPtr compressor_stream) : m_output_stream(move(stream)) , m_compressor(move(compressor_stream)) { @@ -164,7 +164,7 @@ ErrorOr ZlibCompressor::finish() ErrorOr ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompressionLevel compression_level) { auto output_stream = TRY(try_make()); - auto zlib_stream = TRY(ZlibCompressor::construct(MaybeOwned(*output_stream), compression_level)); + auto zlib_stream = TRY(ZlibCompressor::construct(MaybeOwned(*output_stream), compression_level)); TRY(zlib_stream->write_entire_buffer(bytes)); diff --git a/Userland/Libraries/LibCompress/Zlib.h b/Userland/Libraries/LibCompress/Zlib.h index a3ca0369d6b..a62420fb171 100644 --- a/Userland/Libraries/LibCompress/Zlib.h +++ b/Userland/Libraries/LibCompress/Zlib.h @@ -61,9 +61,9 @@ private: ReadonlyBytes m_data_bytes; }; -class ZlibCompressor : public Core::Stream::Stream { +class ZlibCompressor : public AK::Stream { public: - static ErrorOr> construct(MaybeOwned, ZlibCompressionLevel = ZlibCompressionLevel::Default); + static ErrorOr> construct(MaybeOwned, ZlibCompressionLevel = ZlibCompressionLevel::Default); ~ZlibCompressor(); virtual ErrorOr read(Bytes) override; @@ -76,12 +76,12 @@ public: static ErrorOr compress_all(ReadonlyBytes bytes, ZlibCompressionLevel = ZlibCompressionLevel::Default); private: - ZlibCompressor(MaybeOwned stream, NonnullOwnPtr compressor_stream); + ZlibCompressor(MaybeOwned stream, NonnullOwnPtr compressor_stream); ErrorOr write_header(ZlibCompressionMethod, ZlibCompressionLevel); bool m_finished { false }; - MaybeOwned m_output_stream; - NonnullOwnPtr m_compressor; + MaybeOwned m_output_stream; + NonnullOwnPtr m_compressor; Crypto::Checksum::Adler32 m_adler32_checksum; }; diff --git a/Userland/Libraries/LibCore/BitStream.h b/Userland/Libraries/LibCore/BitStream.h index db2f0c0c59e..4610df32e78 100644 --- a/Userland/Libraries/LibCore/BitStream.h +++ b/Userland/Libraries/LibCore/BitStream.h @@ -22,7 +22,7 @@ namespace Core::Stream { /// A stream wrapper class that allows you to read arbitrary amounts of bits /// in big-endian order from another stream. -class BigEndianInputBitStream : public Stream { +class BigEndianInputBitStream : public AK::Stream { public: static ErrorOr> construct(MaybeOwned stream) { @@ -131,7 +131,7 @@ private: /// A stream wrapper class that allows you to read arbitrary amounts of bits /// in little-endian order from another stream. -class LittleEndianInputBitStream : public Stream { +class LittleEndianInputBitStream : public AK::Stream { public: static ErrorOr> construct(MaybeOwned stream) { @@ -240,7 +240,7 @@ private: /// A stream wrapper class that allows you to write arbitrary amounts of bits /// in big-endian order to another stream. -class BigEndianOutputBitStream : public Stream { +class BigEndianOutputBitStream : public AK::Stream { public: static ErrorOr> construct(MaybeOwned stream) { @@ -323,7 +323,7 @@ private: /// A stream wrapper class that allows you to write arbitrary amounts of bits /// in little-endian order to another stream. -class LittleEndianOutputBitStream : public Stream { +class LittleEndianOutputBitStream : public AK::Stream { public: static ErrorOr> construct(MaybeOwned stream) { diff --git a/Userland/Libraries/LibCore/ConfigFile.cpp b/Userland/Libraries/LibCore/ConfigFile.cpp index ef0567b6471..e0f3d734239 100644 --- a/Userland/Libraries/LibCore/ConfigFile.cpp +++ b/Userland/Libraries/LibCore/ConfigFile.cpp @@ -176,7 +176,7 @@ ErrorOr ConfigFile::sync() return Error::from_errno(ENOENT); 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) { TRY(m_file->write(DeprecatedString::formatted("[{}]\n", it.key).bytes())); diff --git a/Userland/Libraries/LibCore/Forward.h b/Userland/Libraries/LibCore/Forward.h index 152b5761c9a..15e45cc4055 100644 --- a/Userland/Libraries/LibCore/Forward.h +++ b/Userland/Libraries/LibCore/Forward.h @@ -40,7 +40,6 @@ enum class TimerShouldFireWhenNotVisible; namespace Stream { class File; class Socket; -class Stream; class BufferedSocketBase; } diff --git a/Userland/Libraries/LibCore/IODevice.h b/Userland/Libraries/LibCore/IODevice.h index e3cda9d68a8..8223f5d84f1 100644 --- a/Userland/Libraries/LibCore/IODevice.h +++ b/Userland/Libraries/LibCore/IODevice.h @@ -9,6 +9,7 @@ #include #include +#include #include namespace Core { @@ -62,12 +63,6 @@ enum class OpenMode : unsigned { KeepOnExec = 32, }; -enum class SeekMode { - SetPosition, - FromCurrentPosition, - FromEndPosition, -}; - AK_ENUM_BITWISE_OPERATORS(OpenMode) class IODevice : public Object { diff --git a/Userland/Libraries/LibCore/MemoryStream.h b/Userland/Libraries/LibCore/MemoryStream.h index 9ae0f53b54e..f712a198b03 100644 --- a/Userland/Libraries/LibCore/MemoryStream.h +++ b/Userland/Libraries/LibCore/MemoryStream.h @@ -49,7 +49,7 @@ private: /// A stream class that allows for writing to an automatically allocating memory area /// and reading back the written data afterwards. -class AllocatingMemoryStream final : public Stream { +class AllocatingMemoryStream final : public AK::Stream { public: virtual ErrorOr read(Bytes) override; virtual ErrorOr write(ReadonlyBytes) override; diff --git a/Userland/Libraries/LibCore/NetworkJob.cpp b/Userland/Libraries/LibCore/NetworkJob.cpp index 8a18f85002a..3169c0b8466 100644 --- a/Userland/Libraries/LibCore/NetworkJob.cpp +++ b/Userland/Libraries/LibCore/NetworkJob.cpp @@ -11,7 +11,7 @@ namespace Core { -NetworkJob::NetworkJob(Core::Stream::Stream& output_stream) +NetworkJob::NetworkJob(AK::Stream& output_stream) : m_output_stream(output_stream) { } diff --git a/Userland/Libraries/LibCore/NetworkJob.h b/Userland/Libraries/LibCore/NetworkJob.h index 24c8f9044a6..7d561bea20d 100644 --- a/Userland/Libraries/LibCore/NetworkJob.h +++ b/Userland/Libraries/LibCore/NetworkJob.h @@ -52,7 +52,7 @@ public: } protected: - NetworkJob(Core::Stream::Stream&); + NetworkJob(AK::Stream&); void did_finish(NonnullRefPtr&&); void did_fail(Error); void did_progress(Optional total_size, u32 downloaded); @@ -61,7 +61,7 @@ protected: private: RefPtr m_response; - Core::Stream::Stream& m_output_stream; + AK::Stream& m_output_stream; Error m_error { Error::None }; }; diff --git a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp index 3818022d509..cb6726cc446 100644 --- a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp +++ b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp @@ -15,9 +15,9 @@ namespace Core { HashMap ProcessStatisticsReader::s_usernames; -ErrorOr ProcessStatisticsReader::get_all(Core::Stream::SeekableStream& proc_all_file, bool include_usernames) +ErrorOr 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; diff --git a/Userland/Libraries/LibCore/ProcessStatisticsReader.h b/Userland/Libraries/LibCore/ProcessStatisticsReader.h index a5d4c9a6797..7bf81bf15bb 100644 --- a/Userland/Libraries/LibCore/ProcessStatisticsReader.h +++ b/Userland/Libraries/LibCore/ProcessStatisticsReader.h @@ -72,7 +72,7 @@ struct AllProcessesStatistics { class ProcessStatisticsReader { public: - static ErrorOr get_all(Core::Stream::SeekableStream&, bool include_usernames = true); + static ErrorOr get_all(SeekableStream&, bool include_usernames = true); static ErrorOr get_all(bool include_usernames = true); private: diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index c54b8891a48..4d68880315d 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -22,124 +22,6 @@ namespace Core::Stream { -ErrorOr 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 Stream::read_until_eof(size_t block_size) -{ - return read_until_eof_impl(block_size); -} - -ErrorOr 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 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 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 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 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(this)->seek(0, SeekMode::FromCurrentPosition); -} - -ErrorOr 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 SeekableStream::discard(size_t discarded_bytes) -{ - TRY(seek(discarded_bytes, SeekMode::FromCurrentPosition)); - return {}; -} - ErrorOr> File::open(StringView filename, OpenMode mode, mode_t permissions) { 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) { } @@ -826,7 +708,7 @@ bool WrapInAKInputStream::discard_or_error(size_t count) return true; } -WrapInAKOutputStream::WrapInAKOutputStream(Core::Stream::Stream& stream) +WrapInAKOutputStream::WrapInAKOutputStream(AK::Stream& stream) : m_stream(stream) { } diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index 0e58741b9b2..58361c51791 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -27,119 +28,6 @@ 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 read(Bytes) = 0; - /// Tries to fill the entire buffer through reading. Returns whether the - /// buffer was filled without an error. - virtual ErrorOr 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 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 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 write(ReadonlyBytes) = 0; - /// Same as write, but does not return until either the entire buffer - /// contents are written or an error occurs. - virtual ErrorOr write_entire_buffer(ReadonlyBytes); - - template - requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs>; }) - ErrorOr read_value() - { - return T::read_from_stream(*this); - } - - template - requires(Traits::is_trivially_serializable()) - ErrorOr read_value() - { - alignas(T) u8 buffer[sizeof(T)] = {}; - TRY(read_entire_buffer({ &buffer, sizeof(buffer) })); - return bit_cast(buffer); - } - - template - requires(requires(T t, Stream& stream) { { t.write_to_stream(stream) } -> SameAs>; }) - ErrorOr write_value(T const& value) - { - return value.write_to_stream(*this); - } - - template - requires(Traits::is_trivially_serializable()) - ErrorOr 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 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 seek(i64 offset, SeekMode) = 0; - /// Returns the current position of the file, or an errno in the case of - /// an error. - virtual ErrorOr 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(); - /// Shrinks or extends the stream to the given size. Returns an errno in - /// the case of an error. - virtual ErrorOr 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 discard(size_t discarded_bytes) override; -}; - enum class PreventSIGPIPE { No, Yes, @@ -147,7 +35,7 @@ enum class PreventSIGPIPE { /// 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. -class Socket : public Stream { +class Socket : public AK::Stream { public: Socket(Socket&&) = default; Socket& operator=(Socket&&) = default; @@ -577,7 +465,7 @@ private: // Buffered stream wrappers template -concept StreamLike = IsBaseOf; +concept StreamLike = IsBaseOf; template concept SeekableStreamLike = IsBaseOf; template @@ -1028,7 +916,7 @@ using ReusableTCPSocket = BasicReusableSocket; using ReusableUDPSocket = BasicReusableSocket; // 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: WrappedAKInputStream(NonnullOwnPtr stream); virtual ErrorOr 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. -class WrappedAKOutputStream final : public Stream { +class WrappedAKOutputStream final : public AK::Stream { public: WrappedAKOutputStream(NonnullOwnPtr stream); virtual ErrorOr 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. class WrapInAKInputStream final : public DeprecatedInputStream { public: - WrapInAKInputStream(Core::Stream::Stream& stream); + WrapInAKInputStream(AK::Stream& stream); virtual size_t read(Bytes) override; virtual bool unreliable_eof() const override; virtual bool read_or_error(Bytes) override; virtual bool discard_or_error(size_t count) override; 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. class WrapInAKOutputStream final : public DeprecatedOutputStream { public: - WrapInAKOutputStream(Core::Stream::Stream& stream); + WrapInAKOutputStream(AK::Stream& stream); virtual size_t write(ReadonlyBytes) override; virtual bool write_or_error(ReadonlyBytes) override; private: - Core::Stream::Stream& m_stream; + AK::Stream& m_stream; }; } diff --git a/Userland/Libraries/LibDNS/Name.cpp b/Userland/Libraries/LibDNS/Name.cpp index 39ee9ae0cc0..ddd42bc82d8 100644 --- a/Userland/Libraries/LibDNS/Name.cpp +++ b/Userland/Libraries/LibDNS/Name.cpp @@ -75,7 +75,7 @@ void Name::randomize_case() m_name = builder.to_deprecated_string(); } -ErrorOr Name::write_to_stream(Core::Stream::Stream& stream) const +ErrorOr Name::write_to_stream(AK::Stream& stream) const { auto parts = as_string().split_view('.'); for (auto& part : parts) { diff --git a/Userland/Libraries/LibDNS/Name.h b/Userland/Libraries/LibDNS/Name.h index 0ad3c3a54fb..fab808d32f6 100644 --- a/Userland/Libraries/LibDNS/Name.h +++ b/Userland/Libraries/LibDNS/Name.h @@ -22,7 +22,7 @@ public: size_t serialized_size() const; DeprecatedString const& as_string() const { return m_name; } - ErrorOr write_to_stream(Core::Stream::Stream&) const; + ErrorOr write_to_stream(AK::Stream&) const; void randomize_case(); diff --git a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp index 8f005569782..ea472cb361c 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.cpp @@ -11,7 +11,7 @@ namespace Debug::Dwarf { -AddressRangesV5::AddressRangesV5(NonnullOwnPtr range_lists_stream, CompilationUnit const& compilation_unit) +AddressRangesV5::AddressRangesV5(NonnullOwnPtr range_lists_stream, CompilationUnit const& compilation_unit) : m_range_lists_stream(move(range_lists_stream)) , m_compilation_unit(compilation_unit) { @@ -85,7 +85,7 @@ ErrorOr AddressRangesV5::for_each_range(Function callback) return {}; } -AddressRangesV4::AddressRangesV4(NonnullOwnPtr ranges_stream, CompilationUnit const& compilation_unit) +AddressRangesV4::AddressRangesV4(NonnullOwnPtr ranges_stream, CompilationUnit const& compilation_unit) : m_ranges_stream(move(ranges_stream)) , m_compilation_unit(compilation_unit) { diff --git a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h index 6439d42bd40..4f4a82985fa 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h +++ b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h @@ -24,12 +24,12 @@ class AddressRangesV5 { AK_MAKE_NONMOVABLE(AddressRangesV5); public: - AddressRangesV5(NonnullOwnPtr range_lists_stream, CompilationUnit const& compilation_unit); + AddressRangesV5(NonnullOwnPtr range_lists_stream, CompilationUnit const& compilation_unit); ErrorOr for_each_range(Function); private: - NonnullOwnPtr m_range_lists_stream; + NonnullOwnPtr m_range_lists_stream; CompilationUnit const& m_compilation_unit; }; @@ -38,12 +38,12 @@ class AddressRangesV4 { AK_MAKE_NONMOVABLE(AddressRangesV4); public: - AddressRangesV4(NonnullOwnPtr ranges_stream, CompilationUnit const&); + AddressRangesV4(NonnullOwnPtr ranges_stream, CompilationUnit const&); ErrorOr for_each_range(Function); private: - NonnullOwnPtr m_ranges_stream; + NonnullOwnPtr m_ranges_stream; CompilationUnit const& m_compilation_unit; }; diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index 485a2e61514..4a7fd797f36 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -80,7 +80,7 @@ ErrorOr DwarfInfo::populate_compilation_units() } ErrorOr 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; value.m_form = form; diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h index 48282f20d7b..2c2cff07afc 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h @@ -43,7 +43,7 @@ public: ErrorOr for_each_compilation_unit(Callback) const; ErrorOr 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> get_die_at_address(FlatPtr) const; diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h b/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h index 44257995e43..67419fb3d3b 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfTypes.h @@ -54,7 +54,7 @@ struct [[gnu::packed]] CompilationUnitHeader { 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; } - static ErrorOr read_from_stream(Core::Stream::Stream& stream) + static ErrorOr read_from_stream(AK::Stream& stream) { CompilationUnitHeader header; TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) })); diff --git a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp index 0b23eccb484..c84a5a656d9 100644 --- a/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/LineProgram.cpp @@ -14,7 +14,7 @@ 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_stream(stream) { diff --git a/Userland/Libraries/LibDebug/Dwarf/LineProgram.h b/Userland/Libraries/LibDebug/Dwarf/LineProgram.h index b12a206f9e1..fb4c678fc10 100644 --- a/Userland/Libraries/LibDebug/Dwarf/LineProgram.h +++ b/Userland/Libraries/LibDebug/Dwarf/LineProgram.h @@ -66,7 +66,7 @@ struct [[gnu::packed]] LineProgramUnitHeader32 { 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; } - static ErrorOr read_from_stream(Core::Stream::Stream& stream) + static ErrorOr read_from_stream(AK::Stream& stream) { LineProgramUnitHeader32 header; TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) })); @@ -109,7 +109,7 @@ class LineProgram { AK_MAKE_NONMOVABLE(LineProgram); public: - explicit LineProgram(DwarfInfo& dwarf_info, Core::Stream::SeekableStream& stream); + explicit LineProgram(DwarfInfo& dwarf_info, SeekableStream& stream); struct LineInfo { FlatPtr address { 0 }; @@ -174,7 +174,7 @@ private: static constexpr u16 MAX_DWARF_VERSION = 5; DwarfInfo& m_dwarf_info; - Core::Stream::SeekableStream& m_stream; + SeekableStream& m_stream; size_t m_unit_offset { 0 }; LineProgramUnitHeader32 m_unit_header {}; diff --git a/Userland/Libraries/LibGemini/Job.cpp b/Userland/Libraries/LibGemini/Job.cpp index 83ab0aad74f..4abb1917bf6 100644 --- a/Userland/Libraries/LibGemini/Job.cpp +++ b/Userland/Libraries/LibGemini/Job.cpp @@ -15,7 +15,7 @@ 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) , m_request(request) { diff --git a/Userland/Libraries/LibGemini/Job.h b/Userland/Libraries/LibGemini/Job.h index 510a2dd77b6..c9a4d99be94 100644 --- a/Userland/Libraries/LibGemini/Job.h +++ b/Userland/Libraries/LibGemini/Job.h @@ -17,7 +17,7 @@ class Job : public Core::NetworkJob { C_OBJECT(Job); public: - explicit Job(GeminiRequest const&, Core::Stream::Stream&); + explicit Job(GeminiRequest const&, AK::Stream&); virtual ~Job() override = default; virtual void start(Core::Stream::Socket&) override; diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 9f8d236efcf..9b3f55db43c 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -89,7 +89,7 @@ enum class GIFFormat { GIF89a, }; -static ErrorOr decode_gif_header(Core::Stream::Stream& stream) +static ErrorOr decode_gif_header(AK::Stream& stream) { static auto valid_header_87 = "GIF87a"sv; static auto valid_header_89 = "GIF89a"sv; diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index 7e069304229..1e4be054995 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -459,7 +459,7 @@ static inline bool is_valid_marker(const Marker marker) return false; } -static inline ErrorOr read_marker_at_cursor(Core::Stream::Stream& stream) +static inline ErrorOr read_marker_at_cursor(AK::Stream& stream) { u16 marker = TRY(stream.read_value>()); if (is_valid_marker(marker)) @@ -476,7 +476,7 @@ static inline ErrorOr read_marker_at_cursor(Core::Stream::Stream& stream return is_valid_marker(marker) ? marker : JPG_INVALID; } -static ErrorOr read_start_of_scan(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr read_start_of_scan(AK::SeekableStream& stream, JPGLoadingContext& context) { if (context.state < JPGLoadingContext::State::FrameDecoded) { dbgln_if(JPG_DEBUG, "{}: SOS found before reading a SOF!", TRY(stream.tell())); @@ -537,7 +537,7 @@ static ErrorOr read_start_of_scan(Core::Stream::SeekableStream& stream, JP return {}; } -static ErrorOr read_reset_marker(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr read_reset_marker(AK::SeekableStream& stream, JPGLoadingContext& context) { u16 bytes_to_read = TRY(stream.read_value>()) - 2; if (bytes_to_read != 2) { @@ -548,7 +548,7 @@ static ErrorOr read_reset_marker(Core::Stream::SeekableStream& stream, JPG return {}; } -static ErrorOr read_huffman_table(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr read_huffman_table(AK::SeekableStream& stream, JPGLoadingContext& context) { i32 bytes_to_read = TRY(stream.read_value>()); TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); @@ -600,7 +600,7 @@ static ErrorOr read_huffman_table(Core::Stream::SeekableStream& stream, JP return {}; } -static ErrorOr read_icc_profile(Core::Stream::SeekableStream& stream, JPGLoadingContext& context, int bytes_to_read) +static ErrorOr read_icc_profile(SeekableStream& stream, JPGLoadingContext& context, int bytes_to_read) { if (bytes_to_read <= 2) return Error::from_string_literal("icc marker too small"); @@ -658,7 +658,7 @@ static ErrorOr read_icc_profile(Core::Stream::SeekableStream& stream, JPGL return {}; } -static ErrorOr read_app_marker(Core::Stream::SeekableStream& stream, JPGLoadingContext& context, int app_marker_number) +static ErrorOr read_app_marker(SeekableStream& stream, JPGLoadingContext& context, int app_marker_number) { i32 bytes_to_read = TRY(stream.read_value>()); 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; } -static ErrorOr read_start_of_frame(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr read_start_of_frame(AK::SeekableStream& stream, JPGLoadingContext& context) { if (context.state == JPGLoadingContext::FrameDecoded) { dbgln_if(JPG_DEBUG, "{}: SOF repeated!", TRY(stream.tell())); @@ -802,7 +802,7 @@ static ErrorOr read_start_of_frame(Core::Stream::SeekableStream& stream, J return {}; } -static ErrorOr read_quantization_table(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr read_quantization_table(AK::SeekableStream& stream, JPGLoadingContext& context) { i32 bytes_to_read = TRY(stream.read_value>()) - 2; TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); @@ -838,7 +838,7 @@ static ErrorOr read_quantization_table(Core::Stream::SeekableStream& strea return {}; } -static ErrorOr skip_marker_with_length(Core::Stream::Stream& stream) +static ErrorOr skip_marker_with_length(AK::Stream& stream) { u16 bytes_to_skip = TRY(stream.read_value>()) - 2; TRY(stream.discard(bytes_to_skip)); @@ -1086,7 +1086,7 @@ static ErrorOr compose_bitmap(JPGLoadingContext& context, Vector parse_header(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr parse_header(AK::SeekableStream& stream, JPGLoadingContext& context) { auto marker = TRY(read_marker_at_cursor(stream)); if (marker != JPG_SOI) { @@ -1163,7 +1163,7 @@ static ErrorOr parse_header(Core::Stream::SeekableStream& stream, JPGLoadi VERIFY_NOT_REACHED(); } -static ErrorOr scan_huffman_stream(Core::Stream::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingContext& context) { u8 last_byte; u8 current_byte = TRY(stream.read_value()); diff --git a/Userland/Libraries/LibGfx/QOILoader.cpp b/Userland/Libraries/LibGfx/QOILoader.cpp index 7ed1e1d71a4..d55a9385447 100644 --- a/Userland/Libraries/LibGfx/QOILoader.cpp +++ b/Userland/Libraries/LibGfx/QOILoader.cpp @@ -21,7 +21,7 @@ static constexpr u8 QOI_OP_RUN = 0b11000000; static constexpr u8 QOI_MASK_2 = 0b11000000; static constexpr u8 END_MARKER[] = { 0, 0, 0, 0, 0, 0, 0, 1 }; -static ErrorOr decode_qoi_header(Core::Stream::Stream& stream) +static ErrorOr decode_qoi_header(AK::Stream& stream) { auto header = TRY(stream.read_value()); if (StringView { header.magic, array_size(header.magic) } != QOI_MAGIC) @@ -31,7 +31,7 @@ static ErrorOr decode_qoi_header(Core::Stream::Stream& stream) return header; } -static ErrorOr decode_qoi_op_rgb(Core::Stream::Stream& stream, u8 first_byte, Color pixel) +static ErrorOr decode_qoi_op_rgb(AK::Stream& stream, u8 first_byte, Color pixel) { VERIFY(first_byte == QOI_OP_RGB); u8 bytes[3]; @@ -41,7 +41,7 @@ static ErrorOr decode_qoi_op_rgb(Core::Stream::Stream& stream, u8 first_b return Color { bytes[0], bytes[1], bytes[2], pixel.alpha() }; } -static ErrorOr decode_qoi_op_rgba(Core::Stream::Stream& stream, u8 first_byte) +static ErrorOr decode_qoi_op_rgba(AK::Stream& stream, u8 first_byte) { VERIFY(first_byte == QOI_OP_RGBA); u8 bytes[4]; @@ -49,7 +49,7 @@ static ErrorOr decode_qoi_op_rgba(Core::Stream::Stream& stream, u8 first_ return Color { bytes[0], bytes[1], bytes[2], bytes[3] }; } -static ErrorOr decode_qoi_op_index(Core::Stream::Stream&, u8 first_byte) +static ErrorOr decode_qoi_op_index(AK::Stream&, u8 first_byte) { VERIFY((first_byte & QOI_MASK_2) == QOI_OP_INDEX); u8 index = first_byte & ~QOI_MASK_2; @@ -57,7 +57,7 @@ static ErrorOr decode_qoi_op_index(Core::Stream::Stream&, u8 first_byte) return index; } -static ErrorOr decode_qoi_op_diff(Core::Stream::Stream&, u8 first_byte, Color pixel) +static ErrorOr decode_qoi_op_diff(AK::Stream&, u8 first_byte, Color pixel) { VERIFY((first_byte & QOI_MASK_2) == QOI_OP_DIFF); u8 dr = (first_byte & 0b00110000) >> 4; @@ -74,7 +74,7 @@ static ErrorOr decode_qoi_op_diff(Core::Stream::Stream&, u8 first_byte, C }; } -static ErrorOr decode_qoi_op_luma(Core::Stream::Stream& stream, u8 first_byte, Color pixel) +static ErrorOr decode_qoi_op_luma(AK::Stream& stream, u8 first_byte, Color pixel) { VERIFY((first_byte & QOI_MASK_2) == QOI_OP_LUMA); auto byte = TRY(stream.read_value()); @@ -91,7 +91,7 @@ static ErrorOr decode_qoi_op_luma(Core::Stream::Stream& stream, u8 first_ }; } -static ErrorOr decode_qoi_op_run(Core::Stream::Stream&, u8 first_byte) +static ErrorOr decode_qoi_op_run(AK::Stream&, u8 first_byte) { VERIFY((first_byte & QOI_MASK_2) == QOI_OP_RUN); u8 run = first_byte & ~QOI_MASK_2; @@ -107,7 +107,7 @@ static ErrorOr decode_qoi_op_run(Core::Stream::Stream&, u8 first_byte) return run; } -static ErrorOr decode_qoi_end_marker(Core::Stream::Stream& stream) +static ErrorOr decode_qoi_end_marker(AK::Stream& stream) { u8 bytes[array_size(END_MARKER)]; TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) })); @@ -118,7 +118,7 @@ static ErrorOr decode_qoi_end_marker(Core::Stream::Stream& stream) return {}; } -static ErrorOr> decode_qoi_image(Core::Stream::Stream& stream, u32 width, u32 height) +static ErrorOr> decode_qoi_image(AK::Stream& stream, u32 width, u32 height) { // FIXME: Why is Gfx::Bitmap's size signed? Makes no sense whatsoever. if (width > NumericLimits::max()) @@ -162,7 +162,7 @@ static ErrorOr> decode_qoi_image(Core::Stream::Stream& str return { move(bitmap) }; } -QOIImageDecoderPlugin::QOIImageDecoderPlugin(NonnullOwnPtr stream) +QOIImageDecoderPlugin::QOIImageDecoderPlugin(NonnullOwnPtr stream) { m_context = make(); m_context->stream = move(stream); @@ -234,7 +234,7 @@ ErrorOr QOIImageDecoderPlugin::frame(size_t index) return *m_context->error; } -ErrorOr QOIImageDecoderPlugin::decode_header_and_update_context(Core::Stream::Stream& stream) +ErrorOr QOIImageDecoderPlugin::decode_header_and_update_context(AK::Stream& stream) { VERIFY(m_context->state < QOILoadingContext::State::HeaderDecoded); auto error_or_header = decode_qoi_header(stream); @@ -248,7 +248,7 @@ ErrorOr QOIImageDecoderPlugin::decode_header_and_update_context(Core::Stre return {}; } -ErrorOr QOIImageDecoderPlugin::decode_image_and_update_context(Core::Stream::Stream& stream) +ErrorOr QOIImageDecoderPlugin::decode_image_and_update_context(AK::Stream& stream) { VERIFY(m_context->state < QOILoadingContext::State::ImageDecoded); auto error_or_bitmap = decode_qoi_image(stream, m_context->header.width, m_context->header.height); diff --git a/Userland/Libraries/LibGfx/QOILoader.h b/Userland/Libraries/LibGfx/QOILoader.h index 05925beb1da..4faa1ad91a6 100644 --- a/Userland/Libraries/LibGfx/QOILoader.h +++ b/Userland/Libraries/LibGfx/QOILoader.h @@ -32,7 +32,7 @@ struct QOILoadingContext { Error, }; State state { State::NotDecoded }; - OwnPtr stream {}; + OwnPtr stream {}; QOIHeader header {}; RefPtr bitmap; Optional error; @@ -56,10 +56,10 @@ public: virtual ErrorOr> icc_data() override; private: - ErrorOr decode_header_and_update_context(Core::Stream::Stream&); - ErrorOr decode_image_and_update_context(Core::Stream::Stream&); + ErrorOr decode_header_and_update_context(AK::Stream&); + ErrorOr decode_image_and_update_context(AK::Stream&); - QOIImageDecoderPlugin(NonnullOwnPtr); + QOIImageDecoderPlugin(NonnullOwnPtr); OwnPtr m_context; }; diff --git a/Userland/Libraries/LibHTTP/HttpsJob.h b/Userland/Libraries/LibHTTP/HttpsJob.h index a9ea47e6d00..e7972287257 100644 --- a/Userland/Libraries/LibHTTP/HttpsJob.h +++ b/Userland/Libraries/LibHTTP/HttpsJob.h @@ -31,7 +31,7 @@ public: Function()> on_certificate_requested; private: - explicit HttpsJob(HttpRequest&& request, Core::Stream::Stream& output_stream) + explicit HttpsJob(HttpRequest&& request, AK::Stream& output_stream) : Job(move(request), output_stream) { } diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 37f5a969534..8c34e575203 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -86,7 +86,7 @@ static ErrorOr handle_content_encoding(ByteBuffer const& buf, Deprec return buf; } -Job::Job(HttpRequest&& request, Core::Stream::Stream& output_stream) +Job::Job(HttpRequest&& request, AK::Stream& output_stream) : Core::NetworkJob(output_stream) , m_request(move(request)) { diff --git a/Userland/Libraries/LibHTTP/Job.h b/Userland/Libraries/LibHTTP/Job.h index 853a728a799..ee27ce19e2e 100644 --- a/Userland/Libraries/LibHTTP/Job.h +++ b/Userland/Libraries/LibHTTP/Job.h @@ -19,7 +19,7 @@ class Job : public Core::NetworkJob { C_OBJECT(Job); public: - explicit Job(HttpRequest&&, Core::Stream::Stream&); + explicit Job(HttpRequest&&, AK::Stream&); virtual ~Job() override = default; virtual void start(Core::Stream::Socket&) override; diff --git a/Userland/Libraries/LibIPC/Decoder.h b/Userland/Libraries/LibIPC/Decoder.h index b47edb5e998..7cd7405994a 100644 --- a/Userland/Libraries/LibIPC/Decoder.h +++ b/Userland/Libraries/LibIPC/Decoder.h @@ -32,7 +32,7 @@ inline ErrorOr decode(Decoder&) class Decoder { public: - Decoder(Core::Stream::Stream& stream, Core::Stream::LocalSocket& socket) + Decoder(AK::Stream& stream, Core::Stream::LocalSocket& socket) : m_stream(stream) , m_socket(socket) { @@ -59,7 +59,7 @@ public: Core::Stream::LocalSocket& socket() { return m_socket; } private: - Core::Stream::Stream& m_stream; + AK::Stream& m_stream; Core::Stream::LocalSocket& m_socket; }; diff --git a/Userland/Libraries/LibJS/Print.h b/Userland/Libraries/LibJS/Print.h index 98acb897195..fb5d9495870 100644 --- a/Userland/Libraries/LibJS/Print.h +++ b/Userland/Libraries/LibJS/Print.h @@ -15,7 +15,7 @@ namespace JS { struct PrintContext { JS::VM& vm; - Core::Stream::Stream& stream; + AK::Stream& stream; bool strip_ansi { false }; }; diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 4ee1726c6ca..db1b8f33f6a 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -1574,7 +1574,7 @@ void Editor::strip_styles(bool strip_anchored) m_refresh_needed = true; } -ErrorOr Editor::reposition_cursor(Core::Stream::Stream& stream, bool to_end) +ErrorOr Editor::reposition_cursor(AK::Stream& stream, bool to_end) { auto cursor = m_cursor; auto saved_cursor = m_cursor; @@ -1596,12 +1596,12 @@ ErrorOr Editor::reposition_cursor(Core::Stream::Stream& stream, bool to_en return {}; } -ErrorOr VT::move_absolute(u32 row, u32 col, Core::Stream::Stream& stream) +ErrorOr VT::move_absolute(u32 row, u32 col, AK::Stream& stream) { return stream.write_entire_buffer(DeprecatedString::formatted("\033[{};{}H", row, col).bytes()); } -ErrorOr VT::move_relative(int row, int col, Core::Stream::Stream& stream) +ErrorOr VT::move_relative(int row, int col, AK::Stream& stream) { char x_op = 'A', y_op = 'D'; @@ -1753,7 +1753,7 @@ DeprecatedString Style::to_deprecated_string() const return builder.to_deprecated_string(); } -ErrorOr VT::apply_style(Style const& style, Core::Stream::Stream& stream, bool is_starting) +ErrorOr VT::apply_style(Style const& style, AK::Stream& stream, bool is_starting) { if (is_starting) { TRY(stream.write_entire_buffer(DeprecatedString::formatted("\033[{};{};{}m{}{}{}", @@ -1771,7 +1771,7 @@ ErrorOr VT::apply_style(Style const& style, Core::Stream::Stream& stream, return {}; } -ErrorOr VT::clear_lines(size_t count_above, size_t count_below, Core::Stream::Stream& stream) +ErrorOr VT::clear_lines(size_t count_above, size_t count_below, AK::Stream& stream) { if (count_below + count_above == 0) { TRY(stream.write_entire_buffer("\033[2K"sv.bytes())); @@ -1790,17 +1790,17 @@ ErrorOr VT::clear_lines(size_t count_above, size_t count_below, Core::Stre return {}; } -ErrorOr VT::save_cursor(Core::Stream::Stream& stream) +ErrorOr VT::save_cursor(AK::Stream& stream) { return stream.write_entire_buffer("\033[s"sv.bytes()); } -ErrorOr VT::restore_cursor(Core::Stream::Stream& stream) +ErrorOr VT::restore_cursor(AK::Stream& stream) { return stream.write_entire_buffer("\033[u"sv.bytes()); } -ErrorOr VT::clear_to_end_of_line(Core::Stream::Stream& stream) +ErrorOr VT::clear_to_end_of_line(AK::Stream& stream) { return stream.write_entire_buffer("\033[K"sv.bytes()); } diff --git a/Userland/Libraries/LibLine/Editor.h b/Userland/Libraries/LibLine/Editor.h index 3a2ca0f3c2e..80d8fc127da 100644 --- a/Userland/Libraries/LibLine/Editor.h +++ b/Userland/Libraries/LibLine/Editor.h @@ -393,7 +393,7 @@ private: } void recalculate_origin(); - ErrorOr reposition_cursor(Core::Stream::Stream&, bool to_end = false); + ErrorOr reposition_cursor(AK::Stream&, bool to_end = false); struct CodepointRange { size_t start { 0 }; diff --git a/Userland/Libraries/LibLine/VT.h b/Userland/Libraries/LibLine/VT.h index a674915eeae..27db0f6de16 100644 --- a/Userland/Libraries/LibLine/VT.h +++ b/Userland/Libraries/LibLine/VT.h @@ -13,13 +13,13 @@ namespace Line { namespace VT { -ErrorOr save_cursor(Core::Stream::Stream&); -ErrorOr restore_cursor(Core::Stream::Stream&); -ErrorOr clear_to_end_of_line(Core::Stream::Stream&); -ErrorOr clear_lines(size_t count_above, size_t count_below, Core::Stream::Stream&); -ErrorOr move_relative(int x, int y, Core::Stream::Stream&); -ErrorOr move_absolute(u32 x, u32 y, Core::Stream::Stream&); -ErrorOr apply_style(Style const&, Core::Stream::Stream&, bool is_starting = true); +ErrorOr save_cursor(AK::Stream&); +ErrorOr restore_cursor(AK::Stream&); +ErrorOr clear_to_end_of_line(AK::Stream&); +ErrorOr clear_lines(size_t count_above, size_t count_below, AK::Stream&); +ErrorOr move_relative(int x, int y, AK::Stream&); +ErrorOr move_absolute(u32 x, u32 y, AK::Stream&); +ErrorOr apply_style(Style const&, AK::Stream&, bool is_starting = true); } } diff --git a/Userland/Libraries/LibProtocol/Request.cpp b/Userland/Libraries/LibProtocol/Request.cpp index bde230c289e..882372217da 100644 --- a/Userland/Libraries/LibProtocol/Request.cpp +++ b/Userland/Libraries/LibProtocol/Request.cpp @@ -20,7 +20,7 @@ bool Request::stop() 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); diff --git a/Userland/Libraries/LibProtocol/Request.h b/Userland/Libraries/LibProtocol/Request.h index 4275d198cc1..b42f913bbf9 100644 --- a/Userland/Libraries/LibProtocol/Request.h +++ b/Userland/Libraries/LibProtocol/Request.h @@ -37,7 +37,7 @@ public: int fd() const { return m_fd; } 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; } /// 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 { - InternalStreamData(NonnullOwnPtr stream) + InternalStreamData(NonnullOwnPtr stream) : read_stream(move(stream)) { } - NonnullOwnPtr read_stream; + NonnullOwnPtr read_stream; RefPtr read_notifier; bool success; u32 total_size { 0 }; diff --git a/Userland/Libraries/LibSQL/Heap.cpp b/Userland/Libraries/LibSQL/Heap.cpp index b7a87a8c9e5..ff75f84f5f5 100644 --- a/Userland/Libraries/LibSQL/Heap.cpp +++ b/Userland/Libraries/LibSQL/Heap.cpp @@ -142,9 +142,9 @@ ErrorOr Heap::seek_block(u32 block) } if (block == m_end_of_file) - TRY(m_file->seek(0, Core::Stream::SeekMode::FromEndPosition)); + TRY(m_file->seek(0, SeekMode::FromEndPosition)); else - TRY(m_file->seek(block * BLOCKSIZE, Core::Stream::SeekMode::SetPosition)); + TRY(m_file->seek(block * BLOCKSIZE, SeekMode::SetPosition)); return {}; } diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index 45fd96390d6..46b9dedb742 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -13,7 +13,7 @@ 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()) return ParseError::UnexpectedEof; @@ -21,7 +21,7 @@ ParseError with_eof_check(Core::Stream::Stream const& stream, ParseError error_i } template -static auto parse_vector(Core::Stream::Stream& stream) +static auto parse_vector(AK::Stream& stream) { ScopeLogger logger; if constexpr (requires { T::parse(stream); }) { @@ -72,7 +72,7 @@ static auto parse_vector(Core::Stream::Stream& stream) } } -static ParseResult parse_name(Core::Stream::Stream& stream) +static ParseResult parse_name(AK::Stream& stream) { ScopeLogger logger; auto data = parse_vector(stream); @@ -88,8 +88,8 @@ struct ParseUntilAnyOfResult { Vector values; }; template -static ParseResult> parse_until_any_of(Core::Stream::Stream& stream, Args&... args) -requires(requires(Core::Stream::Stream& stream, Args... args) { T::parse(stream, args...); }) +static ParseResult> parse_until_any_of(AK::Stream& stream, Args&... args) +requires(requires(AK::Stream& stream, Args... args) { T::parse(stream, args...); }) { ScopeLogger logger; ReconsumableStream new_stream { stream }; @@ -118,7 +118,7 @@ requires(requires(Core::Stream::Stream& stream, Args... args) { T::parse(stream, } } -ParseResult ValueType::parse(Core::Stream::Stream& stream) +ParseResult ValueType::parse(AK::Stream& stream) { ScopeLogger logger("ValueType"sv); auto tag_or_error = stream.read_value(); @@ -145,7 +145,7 @@ ParseResult ValueType::parse(Core::Stream::Stream& stream) } } -ParseResult ResultType::parse(Core::Stream::Stream& stream) +ParseResult ResultType::parse(AK::Stream& stream) { ScopeLogger logger("ResultType"sv); auto types = parse_vector(stream); @@ -154,7 +154,7 @@ ParseResult ResultType::parse(Core::Stream::Stream& stream) return ResultType { types.release_value() }; } -ParseResult FunctionType::parse(Core::Stream::Stream& stream) +ParseResult FunctionType::parse(AK::Stream& stream) { ScopeLogger logger("FunctionType"sv); auto tag_or_error = stream.read_value(); @@ -178,7 +178,7 @@ ParseResult FunctionType::parse(Core::Stream::Stream& stream) return FunctionType { parameters_result.release_value(), results_result.release_value() }; } -ParseResult Limits::parse(Core::Stream::Stream& stream) +ParseResult Limits::parse(AK::Stream& stream) { ScopeLogger logger("Limits"sv); auto flag_or_error = stream.read_value(); @@ -207,7 +207,7 @@ ParseResult Limits::parse(Core::Stream::Stream& stream) return Limits { static_cast(min), move(max) }; } -ParseResult MemoryType::parse(Core::Stream::Stream& stream) +ParseResult MemoryType::parse(AK::Stream& stream) { ScopeLogger logger("MemoryType"sv); auto limits_result = Limits::parse(stream); @@ -216,7 +216,7 @@ ParseResult MemoryType::parse(Core::Stream::Stream& stream) return MemoryType { limits_result.release_value() }; } -ParseResult TableType::parse(Core::Stream::Stream& stream) +ParseResult TableType::parse(AK::Stream& stream) { ScopeLogger logger("TableType"sv); auto type_result = ValueType::parse(stream); @@ -230,7 +230,7 @@ ParseResult TableType::parse(Core::Stream::Stream& stream) return TableType { type_result.release_value(), limits_result.release_value() }; } -ParseResult GlobalType::parse(Core::Stream::Stream& stream) +ParseResult GlobalType::parse(AK::Stream& stream) { ScopeLogger logger("GlobalType"sv); auto type_result = ValueType::parse(stream); @@ -249,7 +249,7 @@ ParseResult GlobalType::parse(Core::Stream::Stream& stream) return GlobalType { type_result.release_value(), mutable_ == 0x01 }; } -ParseResult BlockType::parse(Core::Stream::Stream& stream) +ParseResult BlockType::parse(AK::Stream& stream) { ScopeLogger logger("BlockType"sv); auto kind_or_error = stream.read_value(); @@ -282,7 +282,7 @@ ParseResult BlockType::parse(Core::Stream::Stream& stream) return BlockType { TypeIndex(index_value) }; } -ParseResult> Instruction::parse(Core::Stream::Stream& stream, InstructionPointer& ip) +ParseResult> Instruction::parse(AK::Stream& stream, InstructionPointer& ip) { struct NestedInstructionState { Vector prior_instructions; @@ -782,7 +782,7 @@ ParseResult> Instruction::parse(Core::Stream::Stream& stream return resulting_instructions; } -ParseResult CustomSection::parse(Core::Stream::Stream& stream) +ParseResult CustomSection::parse(AK::Stream& stream) { ScopeLogger logger("CustomSection"sv); auto name = parse_name(stream); @@ -808,7 +808,7 @@ ParseResult CustomSection::parse(Core::Stream::Stream& stream) return CustomSection(name.release_value(), move(data_buffer)); } -ParseResult TypeSection::parse(Core::Stream::Stream& stream) +ParseResult TypeSection::parse(AK::Stream& stream) { ScopeLogger logger("TypeSection"sv); auto types = parse_vector(stream); @@ -817,7 +817,7 @@ ParseResult TypeSection::parse(Core::Stream::Stream& stream) return TypeSection { types.release_value() }; } -ParseResult ImportSection::Import::parse(Core::Stream::Stream& stream) +ParseResult ImportSection::Import::parse(AK::Stream& stream) { ScopeLogger logger("Import"sv); auto module = parse_name(stream); @@ -850,7 +850,7 @@ ParseResult ImportSection::Import::parse(Core::Stream::St } } -ParseResult ImportSection::parse(Core::Stream::Stream& stream) +ParseResult ImportSection::parse(AK::Stream& stream) { ScopeLogger logger("ImportSection"sv); auto imports = parse_vector(stream); @@ -859,7 +859,7 @@ ParseResult ImportSection::parse(Core::Stream::Stream& stream) return ImportSection { imports.release_value() }; } -ParseResult FunctionSection::parse(Core::Stream::Stream& stream) +ParseResult FunctionSection::parse(AK::Stream& stream) { ScopeLogger logger("FunctionSection"sv); auto indices = parse_vector(stream); @@ -874,7 +874,7 @@ ParseResult FunctionSection::parse(Core::Stream::Stream& stream return FunctionSection { move(typed_indices) }; } -ParseResult TableSection::Table::parse(Core::Stream::Stream& stream) +ParseResult TableSection::Table::parse(AK::Stream& stream) { ScopeLogger logger("Table"sv); auto type = TableType::parse(stream); @@ -883,7 +883,7 @@ ParseResult TableSection::Table::parse(Core::Stream::Stream return Table { type.release_value() }; } -ParseResult TableSection::parse(Core::Stream::Stream& stream) +ParseResult TableSection::parse(AK::Stream& stream) { ScopeLogger logger("TableSection"sv); auto tables = parse_vector(stream); @@ -892,7 +892,7 @@ ParseResult TableSection::parse(Core::Stream::Stream& stream) return TableSection { tables.release_value() }; } -ParseResult MemorySection::Memory::parse(Core::Stream::Stream& stream) +ParseResult MemorySection::Memory::parse(AK::Stream& stream) { ScopeLogger logger("Memory"sv); auto type = MemoryType::parse(stream); @@ -901,7 +901,7 @@ ParseResult MemorySection::Memory::parse(Core::Stream::St return Memory { type.release_value() }; } -ParseResult MemorySection::parse(Core::Stream::Stream& stream) +ParseResult MemorySection::parse(AK::Stream& stream) { ScopeLogger logger("MemorySection"sv); auto memories = parse_vector(stream); @@ -910,7 +910,7 @@ ParseResult MemorySection::parse(Core::Stream::Stream& stream) return MemorySection { memories.release_value() }; } -ParseResult Expression::parse(Core::Stream::Stream& stream) +ParseResult Expression::parse(AK::Stream& stream) { ScopeLogger logger("Expression"sv); InstructionPointer ip { 0 }; @@ -921,7 +921,7 @@ ParseResult Expression::parse(Core::Stream::Stream& stream) return Expression { move(instructions.value().values) }; } -ParseResult GlobalSection::Global::parse(Core::Stream::Stream& stream) +ParseResult GlobalSection::Global::parse(AK::Stream& stream) { ScopeLogger logger("Global"sv); auto type = GlobalType::parse(stream); @@ -933,7 +933,7 @@ ParseResult GlobalSection::Global::parse(Core::Stream::St return Global { type.release_value(), exprs.release_value() }; } -ParseResult GlobalSection::parse(Core::Stream::Stream& stream) +ParseResult GlobalSection::parse(AK::Stream& stream) { ScopeLogger logger("GlobalSection"sv); auto result = parse_vector(stream); @@ -942,7 +942,7 @@ ParseResult GlobalSection::parse(Core::Stream::Stream& stream) return GlobalSection { result.release_value() }; } -ParseResult ExportSection::Export::parse(Core::Stream::Stream& stream) +ParseResult ExportSection::Export::parse(AK::Stream& stream) { ScopeLogger logger("Export"sv); auto name = parse_name(stream); @@ -973,7 +973,7 @@ ParseResult ExportSection::Export::parse(Core::Stream::St } } -ParseResult ExportSection::parse(Core::Stream::Stream& stream) +ParseResult ExportSection::parse(AK::Stream& stream) { ScopeLogger logger("ExportSection"sv); auto result = parse_vector(stream); @@ -982,7 +982,7 @@ ParseResult ExportSection::parse(Core::Stream::Stream& stream) return ExportSection { result.release_value() }; } -ParseResult StartSection::StartFunction::parse(Core::Stream::Stream& stream) +ParseResult StartSection::StartFunction::parse(AK::Stream& stream) { ScopeLogger logger("StartFunction"sv); auto index = GenericIndexParser::parse(stream); @@ -991,7 +991,7 @@ ParseResult StartSection::StartFunction::parse(Core return StartFunction { index.release_value() }; } -ParseResult StartSection::parse(Core::Stream::Stream& stream) +ParseResult StartSection::parse(AK::Stream& stream) { ScopeLogger logger("StartSection"sv); auto result = StartFunction::parse(stream); @@ -1000,7 +1000,7 @@ ParseResult StartSection::parse(Core::Stream::Stream& stream) return StartSection { result.release_value() }; } -ParseResult ElementSection::SegmentType0::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType0::parse(AK::Stream& stream) { auto expression = Expression::parse(stream); if (expression.is_error()) @@ -1012,7 +1012,7 @@ ParseResult ElementSection::SegmentType0::parse(Co return SegmentType0 { indices.release_value(), Active { 0, expression.release_value() } }; } -ParseResult ElementSection::SegmentType1::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType1::parse(AK::Stream& stream) { auto kind_or_error = stream.read_value(); if (kind_or_error.is_error()) @@ -1028,49 +1028,49 @@ ParseResult ElementSection::SegmentType1::parse(Co return SegmentType1 { indices.release_value() }; } -ParseResult ElementSection::SegmentType2::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType2::parse(AK::Stream& stream) { dbgln("Type 2"); (void)stream; return ParseError::NotImplemented; } -ParseResult ElementSection::SegmentType3::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType3::parse(AK::Stream& stream) { dbgln("Type 3"); (void)stream; return ParseError::NotImplemented; } -ParseResult ElementSection::SegmentType4::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType4::parse(AK::Stream& stream) { dbgln("Type 4"); (void)stream; return ParseError::NotImplemented; } -ParseResult ElementSection::SegmentType5::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType5::parse(AK::Stream& stream) { dbgln("Type 5"); (void)stream; return ParseError::NotImplemented; } -ParseResult ElementSection::SegmentType6::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType6::parse(AK::Stream& stream) { dbgln("Type 6"); (void)stream; return ParseError::NotImplemented; } -ParseResult ElementSection::SegmentType7::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::SegmentType7::parse(AK::Stream& stream) { dbgln("Type 7"); (void)stream; return ParseError::NotImplemented; } -ParseResult ElementSection::Element::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::Element::parse(AK::Stream& stream) { ScopeLogger logger("Element"sv); auto tag_or_error = stream.read_value(); @@ -1139,7 +1139,7 @@ ParseResult ElementSection::Element::parse(Core::Stream } } -ParseResult ElementSection::parse(Core::Stream::Stream& stream) +ParseResult ElementSection::parse(AK::Stream& stream) { ScopeLogger logger("ElementSection"sv); auto result = parse_vector(stream); @@ -1148,7 +1148,7 @@ ParseResult ElementSection::parse(Core::Stream::Stream& stream) return ElementSection { result.release_value() }; } -ParseResult Locals::parse(Core::Stream::Stream& stream) +ParseResult Locals::parse(AK::Stream& stream) { ScopeLogger logger("Locals"sv); size_t count; @@ -1166,7 +1166,7 @@ ParseResult Locals::parse(Core::Stream::Stream& stream) return Locals { static_cast(count), type.release_value() }; } -ParseResult CodeSection::Func::parse(Core::Stream::Stream& stream) +ParseResult CodeSection::Func::parse(AK::Stream& stream) { ScopeLogger logger("Func"sv); auto locals = parse_vector(stream); @@ -1178,7 +1178,7 @@ ParseResult CodeSection::Func::parse(Core::Stream::Stream& st return Func { locals.release_value(), body.release_value() }; } -ParseResult CodeSection::Code::parse(Core::Stream::Stream& stream) +ParseResult CodeSection::Code::parse(AK::Stream& stream) { ScopeLogger logger("Code"sv); size_t size; @@ -1195,7 +1195,7 @@ ParseResult CodeSection::Code::parse(Core::Stream::Stream& st return Code { static_cast(size), func.release_value() }; } -ParseResult CodeSection::parse(Core::Stream::Stream& stream) +ParseResult CodeSection::parse(AK::Stream& stream) { ScopeLogger logger("CodeSection"sv); auto result = parse_vector(stream); @@ -1204,7 +1204,7 @@ ParseResult CodeSection::parse(Core::Stream::Stream& stream) return CodeSection { result.release_value() }; } -ParseResult DataSection::Data::parse(Core::Stream::Stream& stream) +ParseResult DataSection::Data::parse(AK::Stream& stream) { ScopeLogger logger("Data"sv); auto tag_or_error = stream.read_value(); @@ -1246,7 +1246,7 @@ ParseResult DataSection::Data::parse(Core::Stream::Stream& st VERIFY_NOT_REACHED(); } -ParseResult DataSection::parse(Core::Stream::Stream& stream) +ParseResult DataSection::parse(AK::Stream& stream) { ScopeLogger logger("DataSection"sv); auto data = parse_vector(stream); @@ -1256,7 +1256,7 @@ ParseResult DataSection::parse(Core::Stream::Stream& stream) return DataSection { data.release_value() }; } -ParseResult DataCountSection::parse([[maybe_unused]] Core::Stream::Stream& stream) +ParseResult DataCountSection::parse([[maybe_unused]] AK::Stream& stream) { ScopeLogger logger("DataCountSection"sv); u32 value; @@ -1272,7 +1272,7 @@ ParseResult DataCountSection::parse([[maybe_unused]] Core::Str return DataCountSection { value }; } -ParseResult Module::parse(Core::Stream::Stream& stream) +ParseResult Module::parse(AK::Stream& stream) { ScopeLogger logger("Module"sv); u8 buf[4]; diff --git a/Userland/Libraries/LibWasm/Printer/Printer.h b/Userland/Libraries/LibWasm/Printer/Printer.h index a3aa735a628..44b8c28809b 100644 --- a/Userland/Libraries/LibWasm/Printer/Printer.h +++ b/Userland/Libraries/LibWasm/Printer/Printer.h @@ -18,7 +18,7 @@ DeprecatedString instruction_name(OpCode const& opcode); Optional instruction_from_name(StringView name); 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_indent(initial_indent) { @@ -72,7 +72,7 @@ private: 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 }; }; diff --git a/Userland/Libraries/LibWasm/Types.h b/Userland/Libraries/LibWasm/Types.h index 05e8c814b00..725f47cdb4c 100644 --- a/Userland/Libraries/LibWasm/Types.h +++ b/Userland/Libraries/LibWasm/Types.h @@ -59,11 +59,11 @@ AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, LabelIndex); AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, DataIndex); 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 struct GenericIndexParser { - static ParseResult parse(Core::Stream::Stream& stream) + static ParseResult parse(AK::Stream& stream) { size_t value; Core::Stream::WrapInAKInputStream wrapped_stream { stream }; @@ -73,9 +73,9 @@ struct GenericIndexParser { } }; -class ReconsumableStream : public Core::Stream::Stream { +class ReconsumableStream : public AK::Stream { public: - explicit ReconsumableStream(Core::Stream::Stream& stream) + explicit ReconsumableStream(AK::Stream& stream) : m_stream(stream) { } @@ -133,13 +133,13 @@ private: m_stream.close(); } - Core::Stream::Stream& m_stream; + AK::Stream& m_stream; Vector m_buffer; }; -class ConstrainedStream : public Core::Stream::Stream { +class ConstrainedStream : public AK::Stream { public: - explicit ConstrainedStream(Core::Stream::Stream& stream, size_t size) + explicit ConstrainedStream(AK::Stream& stream, size_t size) : m_stream(stream) , m_bytes_left(size) { @@ -182,7 +182,7 @@ private: m_stream.close(); } - Core::Stream::Stream& m_stream; + AK::Stream& m_stream; size_t m_bytes_left { 0 }; }; @@ -211,7 +211,7 @@ public: auto is_numeric() const { return !is_reference(); } auto kind() const { return m_kind; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); static DeprecatedString kind_name(Kind kind) { @@ -250,7 +250,7 @@ public: auto const& types() const { return m_types; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_types; @@ -268,7 +268,7 @@ public: auto& parameters() const { return m_parameters; } auto& results() const { return m_results; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_parameters; @@ -287,7 +287,7 @@ public: auto min() const { return m_min; } auto& max() const { return m_max; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: u32 m_min { 0 }; @@ -304,7 +304,7 @@ public: auto& limits() const { return m_limits; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Limits m_limits; @@ -323,7 +323,7 @@ public: auto& limits() const { return m_limits; } auto& element_type() const { return m_element_type; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: ValueType m_element_type; @@ -342,7 +342,7 @@ public: auto& type() const { return m_type; } auto is_mutable() const { return m_is_mutable; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: ValueType m_type; @@ -388,7 +388,7 @@ public: return m_type_index; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Kind m_kind { Empty }; @@ -452,7 +452,7 @@ public: { } - static ParseResult> parse(Core::Stream::Stream& stream, InstructionPointer& ip); + static ParseResult> parse(AK::Stream& stream, InstructionPointer& ip); auto& opcode() const { return m_opcode; } auto& arguments() const { return m_arguments; } @@ -499,7 +499,7 @@ public: auto& name() const { return m_name; } auto& contents() const { return m_contents; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: DeprecatedString m_name; @@ -517,7 +517,7 @@ public: auto& types() const { return m_types; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_types; @@ -539,7 +539,7 @@ public: auto& name() const { return m_name; } auto& description() const { return m_description; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: template @@ -566,7 +566,7 @@ public: auto& imports() const { return m_imports; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_imports; @@ -583,7 +583,7 @@ public: auto& types() const { return m_types; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_types; @@ -600,7 +600,7 @@ public: auto& type() const { return m_type; } - static ParseResult
parse(Core::Stream::Stream& stream); + static ParseResult
parse(AK::Stream& stream); private: TableType m_type; @@ -616,7 +616,7 @@ public: auto& tables() const { return m_tables; }; - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector
m_tables; @@ -633,7 +633,7 @@ public: auto& type() const { return m_type; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: MemoryType m_type; @@ -649,7 +649,7 @@ public: auto& memories() const { return m_memories; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_memories; @@ -664,7 +664,7 @@ public: auto& instructions() const { return m_instructions; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_instructions; @@ -683,7 +683,7 @@ public: auto& type() const { return m_type; } auto& expression() const { return m_expression; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: GlobalType m_type; @@ -700,7 +700,7 @@ public: auto& entries() const { return m_entries; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_entries; @@ -722,7 +722,7 @@ public: auto& name() const { return m_name; } auto& description() const { return m_description; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: DeprecatedString m_name; @@ -738,7 +738,7 @@ public: auto& entries() const { return m_entries; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_entries; @@ -755,7 +755,7 @@ public: auto& index() const { return m_index; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: FunctionIndex m_index; @@ -770,7 +770,7 @@ public: auto& function() const { return m_function; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: StartFunction m_function; @@ -789,43 +789,43 @@ public: struct SegmentType0 { // FIXME: Implement me! - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); Vector function_indices; Active mode; }; struct SegmentType1 { - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); Vector function_indices; }; struct SegmentType2 { // FIXME: Implement me! - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); }; struct SegmentType3 { // FIXME: Implement me! - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); }; struct SegmentType4 { // FIXME: Implement me! - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); }; struct SegmentType5 { // FIXME: Implement me! - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); }; struct SegmentType6 { // FIXME: Implement me! - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); }; struct SegmentType7 { // FIXME: Implement me! - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); }; struct Element { - static ParseResult parse(Core::Stream::Stream&); + static ParseResult parse(AK::Stream&); ValueType type; Vector init; @@ -841,7 +841,7 @@ public: auto& segments() const { return m_segments; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_segments; @@ -859,7 +859,7 @@ public: auto n() const { return m_n; } auto& type() const { return m_type; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: u32 m_n { 0 }; @@ -880,7 +880,7 @@ public: auto& locals() const { return m_locals; } auto& body() const { return m_body; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_locals; @@ -897,7 +897,7 @@ public: auto size() const { return m_size; } auto& func() const { return m_func; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: u32 m_size { 0 }; @@ -913,7 +913,7 @@ public: auto& functions() const { return m_functions; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_functions; @@ -940,7 +940,7 @@ public: auto& value() const { return m_value; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Value m_value; @@ -955,7 +955,7 @@ public: auto& data() const { return m_data; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Vector m_data; @@ -972,7 +972,7 @@ public: auto& count() const { return m_count; } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: Optional m_count; @@ -1067,7 +1067,7 @@ public: StringView validation_error() const { return *m_validation_error; } void set_validation_error(DeprecatedString error) { m_validation_error = move(error); } - static ParseResult parse(Core::Stream::Stream& stream); + static ParseResult parse(AK::Stream& stream); private: bool populate_sections(); diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h index 20543c541d3..58819202026 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h @@ -61,7 +61,7 @@ public: virtual void set_should_buffer_all_input(bool) = 0; virtual bool stop() = 0; - virtual void stream_into(Core::Stream::Stream&) = 0; + virtual void stream_into(AK::Stream&) = 0; Function const& response_headers, Optional response_code, ReadonlyBytes payload)> on_buffered_request_finish; Function on_finish; diff --git a/Userland/Libraries/LibWebView/RequestServerAdapter.cpp b/Userland/Libraries/LibWebView/RequestServerAdapter.cpp index 21a87bfdce2..5dcac0eca86 100644 --- a/Userland/Libraries/LibWebView/RequestServerAdapter.cpp +++ b/Userland/Libraries/LibWebView/RequestServerAdapter.cpp @@ -64,7 +64,7 @@ bool RequestServerRequestAdapter::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); } diff --git a/Userland/Libraries/LibWebView/RequestServerAdapter.h b/Userland/Libraries/LibWebView/RequestServerAdapter.h index 7919502fb5b..728e441d840 100644 --- a/Userland/Libraries/LibWebView/RequestServerAdapter.h +++ b/Userland/Libraries/LibWebView/RequestServerAdapter.h @@ -27,7 +27,7 @@ public: virtual void set_should_buffer_all_input(bool) override; virtual bool stop() override; - virtual void stream_into(Core::Stream::Stream&) override; + virtual void stream_into(AK::Stream&) override; private: RequestServerRequestAdapter(NonnullRefPtr); diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp index 33a8eb3b8e7..0804a033ec0 100644 --- a/Userland/Services/WebServer/Client.cpp +++ b/Userland/Services/WebServer/Client.cpp @@ -175,7 +175,7 @@ ErrorOr Client::handle_request(ReadonlyBytes raw_request) return true; } -ErrorOr Client::send_response(Core::Stream::Stream& response, HTTP::HttpRequest const& request, ContentInfo content_info) +ErrorOr Client::send_response(AK::Stream& response, HTTP::HttpRequest const& request, ContentInfo content_info) { StringBuilder builder; builder.append("HTTP/1.0 200 OK\r\n"sv); diff --git a/Userland/Services/WebServer/Client.h b/Userland/Services/WebServer/Client.h index 8f775a4bca6..c62e6191606 100644 --- a/Userland/Services/WebServer/Client.h +++ b/Userland/Services/WebServer/Client.h @@ -30,7 +30,7 @@ private: }; ErrorOr handle_request(ReadonlyBytes); - ErrorOr send_response(Core::Stream::Stream&, HTTP::HttpRequest const&, ContentInfo); + ErrorOr send_response(AK::Stream&, HTTP::HttpRequest const&, ContentInfo); ErrorOr send_redirect(StringView redirect, HTTP::HttpRequest const&); ErrorOr send_error_response(unsigned code, HTTP::HttpRequest const&, Vector const& headers = {}); void die(); diff --git a/Userland/Utilities/gml-format.cpp b/Userland/Utilities/gml-format.cpp index 37d10475fe4..a332fb30512 100644 --- a/Userland/Utilities/gml-format.cpp +++ b/Userland/Utilities/gml-format.cpp @@ -26,7 +26,7 @@ static ErrorOr format_file(StringView path, bool inplace) if (inplace && !read_from_stdin) { if (formatted_gml == contents) return true; - TRY(file->seek(0, Core::Stream::SeekMode::SetPosition)); + TRY(file->seek(0, SeekMode::SetPosition)); TRY(file->truncate(0)); TRY(file->write(formatted_gml.bytes())); } else { diff --git a/Userland/Utilities/gunzip.cpp b/Userland/Utilities/gunzip.cpp index 7eb8dbc6071..1c5b395b0f9 100644 --- a/Userland/Utilities/gunzip.cpp +++ b/Userland/Utilities/gunzip.cpp @@ -10,7 +10,7 @@ #include #include -static ErrorOr decompress_file(NonnullOwnPtr input_stream, Core::Stream::Stream& output_stream) +static ErrorOr decompress_file(NonnullOwnPtr input_stream, AK::Stream& output_stream) { auto gzip_stream = Compress::GzipDecompressor { move(input_stream) }; diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index f3c79e54f42..61dd68acb9f 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -336,7 +336,7 @@ public: return false; } - virtual void stream_into(Core::Stream::Stream&) override + virtual void stream_into(AK::Stream&) override { } @@ -415,7 +415,7 @@ public: return false; } - virtual void stream_into(Core::Stream::Stream&) override + virtual void stream_into(AK::Stream&) override { } @@ -484,7 +484,7 @@ public: return false; } - virtual void stream_into(Core::Stream::Stream&) override + virtual void stream_into(AK::Stream&) override { } diff --git a/Userland/Utilities/hexdump.cpp b/Userland/Utilities/hexdump.cpp index 38214a1efaf..00fe33f4e10 100644 --- a/Userland/Utilities/hexdump.cpp +++ b/Userland/Utilities/hexdump.cpp @@ -39,7 +39,7 @@ ErrorOr serenity_main(Main::Arguments args) auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read)); 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) { VERIFY(line.size() <= LINE_LENGTH_BYTES); diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index c0f1c866078..1399c388e88 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -84,7 +84,7 @@ static DeprecatedString s_history_path = DeprecatedString::formatted("{}/.js-his static int s_repl_line_level = 0; static bool s_fail_repl = false; -static ErrorOr print(JS::Value value, Core::Stream::Stream& stream) +static ErrorOr print(JS::Value value, AK::Stream& stream) { JS::PrintContext print_context { .vm = *g_vm, .stream = stream, .strip_ansi = s_strip_ansi }; return JS::print(value, print_context); diff --git a/Userland/Utilities/pro.cpp b/Userland/Utilities/pro.cpp index 79c6f569298..c02b2660073 100644 --- a/Userland/Utilities/pro.cpp +++ b/Userland/Utilities/pro.cpp @@ -104,9 +104,9 @@ private: /// Wraps a stream to silently ignore writes when the condition isn't true. template -class ConditionalOutputStream final : public Core::Stream::Stream { +class ConditionalOutputStream final : public AK::Stream { public: - ConditionalOutputStream(ConditionT&& condition, MaybeOwned stream) + ConditionalOutputStream(ConditionT&& condition, MaybeOwned stream) : m_stream(move(stream)) , m_condition(condition) { @@ -141,7 +141,7 @@ public: } private: - MaybeOwned m_stream; + MaybeOwned m_stream; ConditionT m_condition; }; diff --git a/Userland/Utilities/tail.cpp b/Userland/Utilities/tail.cpp index 382449957e7..c4a7f1e34b9 100644 --- a/Userland/Utilities/tail.cpp +++ b/Userland/Utilities/tail.cpp @@ -14,7 +14,7 @@ static ErrorOr 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()); out("{}", StringView { buffer }); return {}; @@ -24,13 +24,13 @@ static ErrorOr find_seek_pos(Core::Stream::File& file, int wanted_lines) { // Rather than reading the whole file, start at the end and work backwards, // 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; int lines = 0; for (; pos >= 0; pos--) { - TRY(file.seek(pos, Core::Stream::SeekMode::SetPosition)); + TRY(file.seek(pos, SeekMode::SetPosition)); if (file.is_eof()) break; @@ -102,7 +102,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(tail_from_pos(*f, pos)); if (follow) { - TRY(f->seek(0, Core::Stream::SeekMode::FromEndPosition)); + TRY(f->seek(0, SeekMode::FromEndPosition)); Core::EventLoop event_loop; auto watcher = TRY(Core::FileWatcher::create()); @@ -118,7 +118,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto bytes = buffer_or_error.value().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()) { auto error = potential_error.error(); warnln(error.string_literal()); diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp index 35166cd9b8a..eb4e8045526 100644 --- a/Userland/Utilities/tar.cpp +++ b/Userland/Utilities/tar.cpp @@ -64,7 +64,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (!directory.is_empty()) TRY(Core::System::chdir(directory)); - NonnullOwnPtr input_stream = TRY(Core::Stream::File::open_file_or_standard_stream(archive_file, Core::Stream::OpenMode::Read)); + NonnullOwnPtr input_stream = TRY(Core::Stream::File::open_file_or_standard_stream(archive_file, Core::Stream::OpenMode::Read)); if (gzip) input_stream = make(move(input_stream)); @@ -206,7 +206,7 @@ ErrorOr serenity_main(Main::Arguments arguments) return 1; } - NonnullOwnPtr output_stream = TRY(Core::Stream::File::standard_output()); + NonnullOwnPtr output_stream = TRY(Core::Stream::File::standard_output()); if (!archive_file.is_empty()) output_stream = TRY(Core::Stream::File::open(archive_file, Core::Stream::OpenMode::Write)); diff --git a/Userland/Utilities/utmpupdate.cpp b/Userland/Utilities/utmpupdate.cpp index b7eec59b13d..cc7e282488f 100644 --- a/Userland/Utilities/utmpupdate.cpp +++ b/Userland/Utilities/utmpupdate.cpp @@ -70,7 +70,7 @@ ErrorOr serenity_main(Main::Arguments arguments) json.remove(tty_name); } - TRY(file->seek(0, Core::Stream::SeekMode::SetPosition)); + TRY(file->seek(0, SeekMode::SetPosition)); TRY(file->truncate(0)); TRY(file->write(json.to_deprecated_string().bytes())); diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index 66146bc45b5..e08a2484b1a 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -19,7 +19,7 @@ #include RefPtr g_line_editor; -static OwnPtr g_stdout {}; +static OwnPtr g_stdout {}; static OwnPtr g_printer {}; static bool g_continue { false }; static void (*old_signal)(int);