summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-12-11 17:49:00 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-12 14:16:42 +0100
commited4c2f2f8ea59295edceca77bf308df5de6872d6 (patch)
treec28004c0fcfe0146d40549c74ec256eb50f3eb44 /Userland/Libraries/LibCore
parent5061a905ff561743c7de9c7a413845b714ab4ee2 (diff)
downloadserenity-ed4c2f2f8ea59295edceca77bf308df5de6872d6.zip
LibCore: Rename `Stream::read_all` to `read_until_eof`
This generally seems like a better name, especially if we somehow also need a better name for "read the entire buffer, but not the entire file" somewhere down the line.
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/ProcessStatisticsReader.cpp2
-rw-r--r--Userland/Libraries/LibCore/Stream.cpp10
-rw-r--r--Userland/Libraries/LibCore/Stream.h8
3 files changed, 10 insertions, 10 deletions
diff --git a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp
index 8f2ea44cc0..975e16987c 100644
--- a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp
+++ b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp
@@ -21,7 +21,7 @@ ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(Core::Stream::S
AllProcessesStatistics all_processes_statistics;
- auto file_contents = TRY(proc_all_file.read_all());
+ auto file_contents = TRY(proc_all_file.read_until_eof());
auto json_obj = TRY(JsonValue::from_string(file_contents)).as_object();
json_obj.get("processes"sv).as_array().for_each([&](auto& value) {
const JsonObject& process_object = value.as_object();
diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp
index aab023c26f..ba69c533c7 100644
--- a/Userland/Libraries/LibCore/Stream.cpp
+++ b/Userland/Libraries/LibCore/Stream.cpp
@@ -47,12 +47,12 @@ bool Stream::read_or_error(Bytes buffer)
return true;
}
-ErrorOr<ByteBuffer> Stream::read_all(size_t block_size)
+ErrorOr<ByteBuffer> Stream::read_until_eof(size_t block_size)
{
- return read_all_impl(block_size);
+ return read_until_eof_impl(block_size);
}
-ErrorOr<ByteBuffer> Stream::read_all_impl(size_t block_size, size_t expected_file_size)
+ErrorOr<ByteBuffer> Stream::read_until_eof_impl(size_t block_size, size_t expected_file_size)
{
ByteBuffer data;
data.ensure_capacity(expected_file_size);
@@ -243,12 +243,12 @@ ErrorOr<Bytes> File::read(Bytes buffer)
return buffer.trim(nread);
}
-ErrorOr<ByteBuffer> File::read_all(size_t block_size)
+ErrorOr<ByteBuffer> File::read_until_eof(size_t block_size)
{
// Note: This is used as a heuristic, it's not valid for devices or virtual files.
auto const potential_file_size = TRY(System::fstat(m_fd)).st_size;
- return read_all_impl(block_size, potential_file_size);
+ return read_until_eof_impl(block_size, potential_file_size);
}
ErrorOr<size_t> File::write(ReadonlyBytes buffer)
diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h
index f57bcc0400..550a376e03 100644
--- a/Userland/Libraries/LibCore/Stream.h
+++ b/Userland/Libraries/LibCore/Stream.h
@@ -39,7 +39,7 @@ public:
/// Reads the stream until EOF, storing the contents into a ByteBuffer which
/// is returned once EOF is encountered. The block size determines the size
/// of newly allocated chunks while reading.
- virtual ErrorOr<ByteBuffer> read_all(size_t block_size = 4096);
+ virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096);
/// Discards the given number of bytes from the stream.
/// Unless specifically overwritten, this just uses read() to read into an
/// internal stack-based buffer.
@@ -69,12 +69,12 @@ public:
}
protected:
- /// Provides a default implementation of read_all that works for streams
+ /// Provides a default implementation of read_until_eof that works for streams
/// that behave like POSIX file descriptors. expected_file_size can be
/// passed as a heuristic for what the Stream subclass expects the file
/// content size to be in order to reduce allocations (does not affect
/// actual reading).
- ErrorOr<ByteBuffer> read_all_impl(size_t block_size, size_t expected_file_size = 0);
+ ErrorOr<ByteBuffer> read_until_eof_impl(size_t block_size, size_t expected_file_size = 0);
};
enum class SeekMode {
@@ -238,7 +238,7 @@ public:
}
virtual ErrorOr<Bytes> read(Bytes) override;
- virtual ErrorOr<ByteBuffer> read_all(size_t block_size = 4096) override;
+ virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096) override;
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
virtual bool is_eof() const override;
virtual bool is_open() const override;