1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

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.
This commit is contained in:
Tim Schumacher 2022-12-11 17:49:00 +01:00 committed by Andreas Kling
parent 5061a905ff
commit ed4c2f2f8e
65 changed files with 88 additions and 88 deletions

View file

@ -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();

View file

@ -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)

View file

@ -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;