mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03: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:
parent
5061a905ff
commit
ed4c2f2f8e
Notes:
sideshowbarker
2024-07-17 07:20:57 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/ed4c2f2f8e Pull-request: https://github.com/SerenityOS/serenity/pull/16429 Reviewed-by: https://github.com/sin-ack ✅
@ -19,6 +19,6 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
|
||||
auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream };
|
||||
|
||||
(void)brotli_stream.read_all();
|
||||
(void)brotli_stream.read_until_eof();
|
||||
return 0;
|
||||
}
|
||||
|
@ -826,7 +826,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
auto file = TRY(Core::Stream::File::open(arguments.strings[1], Core::Stream::OpenMode::Read));
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
|
||||
auto endpoints = parse(file_contents);
|
||||
|
||||
|
@ -118,7 +118,7 @@ static ErrorOr<ApprovalDate> parse_approval_date(StringView const& str)
|
||||
|
||||
static ErrorOr<HashMap<DeprecatedString, PnpIdData>> parse_pnp_ids_database(Core::Stream::File& pnp_ids_file)
|
||||
{
|
||||
auto pnp_ids_file_bytes = TRY(pnp_ids_file.read_all());
|
||||
auto pnp_ids_file_bytes = TRY(pnp_ids_file.read_until_eof());
|
||||
StringView pnp_ids_file_contents(pnp_ids_file_bytes);
|
||||
|
||||
HashMap<DeprecatedString, PnpIdData> pnp_id_data;
|
||||
|
@ -337,7 +337,7 @@ inline ErrorOr<NonnullOwnPtr<Core::Stream::BufferedFile>> open_file(StringView p
|
||||
inline ErrorOr<JsonValue> read_json_file(StringView path)
|
||||
{
|
||||
auto file = TRY(open_file(path, Core::Stream::OpenMode::Read));
|
||||
auto buffer = TRY(file->read_all());
|
||||
auto buffer = TRY(file->read_until_eof());
|
||||
|
||||
return JsonValue::from_string(buffer);
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
return Error::from_string_view(s_error_string);
|
||||
}
|
||||
auto file = file_or_error.release_value();
|
||||
auto string = MUST(file->read_all());
|
||||
auto string = MUST(file->read_until_eof());
|
||||
file_contents.append(DeprecatedString(ReadonlyBytes(string)));
|
||||
}
|
||||
VERIFY(paths.size() == file_contents.size());
|
||||
|
@ -222,7 +222,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto content = TRY(file->read_all());
|
||||
auto content = TRY(file->read_until_eof());
|
||||
auto state_machine = parse_state_machine(content);
|
||||
|
||||
StringBuilder builder;
|
||||
|
@ -19,13 +19,13 @@ static void run_test(StringView const file_name)
|
||||
#endif
|
||||
|
||||
auto cmp_file = MUST(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto cmp_data = MUST(cmp_file->read_all());
|
||||
auto cmp_data = MUST(cmp_file->read_until_eof());
|
||||
|
||||
DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path);
|
||||
|
||||
auto file = MUST(Core::Stream::File::open(path_compressed, Core::Stream::OpenMode::Read));
|
||||
auto brotli_stream = Compress::BrotliDecompressionStream { *file };
|
||||
auto data = MUST(brotli_stream.read_all());
|
||||
auto data = MUST(brotli_stream.read_until_eof());
|
||||
|
||||
EXPECT_EQ(data, cmp_data);
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public:
|
||||
|
||||
DeprecatedString read_all()
|
||||
{
|
||||
auto all_output_or_error = m_input->read_all();
|
||||
auto all_output_or_error = m_input->read_until_eof();
|
||||
if (all_output_or_error.is_error()) {
|
||||
warnln("Got error: {} while reading runner output", all_output_or_error.error());
|
||||
return ""sv;
|
||||
|
@ -149,7 +149,7 @@ static Result<StringView, TestError> read_harness_file(StringView harness_file)
|
||||
};
|
||||
}
|
||||
|
||||
auto contents_or_error = file_or_error.value()->read_all();
|
||||
auto contents_or_error = file_or_error.value()->read_until_eof();
|
||||
if (contents_or_error.is_error()) {
|
||||
return TestError {
|
||||
NegativePhase::Harness,
|
||||
@ -719,7 +719,7 @@ int main(int argc, char** argv)
|
||||
static size_t strict_length = use_strict.length();
|
||||
|
||||
{
|
||||
auto contents_or_error = file->read_all();
|
||||
auto contents_or_error = file->read_until_eof();
|
||||
if (contents_or_error.is_error()) {
|
||||
warnln("Could not read contents of file: {}", path);
|
||||
return exit_read_file_failure;
|
||||
|
@ -113,7 +113,7 @@ private:
|
||||
return "";
|
||||
}
|
||||
|
||||
auto file_contents_or_error = file_or_error.value()->read_all();
|
||||
auto file_contents_or_error = file_or_error.value()->read_until_eof();
|
||||
if (file_contents_or_error.is_error()) {
|
||||
dbgln("Error: Could not read /sys/kernel/net/adapters: {}", file_contents_or_error.error());
|
||||
return "";
|
||||
|
@ -153,7 +153,7 @@ private:
|
||||
file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read));
|
||||
}
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
return TRY(JsonValue::from_string(file_contents));
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ NetworkSettingsWidget::NetworkSettingsWidget()
|
||||
auto config_file = Core::ConfigFile::open_for_system("Network").release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
auto proc_net_adapters_file = Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
|
||||
auto data = proc_net_adapters_file->read_all().release_value_but_fixme_should_propagate_errors();
|
||||
auto data = proc_net_adapters_file->read_until_eof().release_value_but_fixme_should_propagate_errors();
|
||||
JsonParser parser(data);
|
||||
JsonValue proc_net_adapters_json = parser.parse().release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
|
@ -67,7 +67,7 @@ ErrorOr<NonnullOwnPtr<Presentation>> Presentation::load_from_file(StringView fil
|
||||
if (file_name.is_empty())
|
||||
return ENOENT;
|
||||
auto file = TRY(Core::Stream::File::open_file_or_standard_stream(file_name, Core::Stream::OpenMode::Read));
|
||||
auto contents = TRY(file->read_all());
|
||||
auto contents = TRY(file->read_until_eof());
|
||||
auto content_string = StringView { contents };
|
||||
auto json = TRY(JsonValue::from_string(content_string));
|
||||
|
||||
|
@ -113,7 +113,7 @@ Image::Image(NonnullRefPtr<ImageDecoderClient::Client> client, NonnullRefPtr<GUI
|
||||
ErrorOr<void> Image::reload_image()
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open(m_image_path, Core::Stream::OpenMode::Read));
|
||||
auto data = TRY(file->read_all());
|
||||
auto data = TRY(file->read_until_eof());
|
||||
auto maybe_decoded = m_client->decode_image(data);
|
||||
if (!maybe_decoded.has_value() || maybe_decoded.value().frames.size() < 1)
|
||||
return Error::from_string_view("Could not decode image"sv);
|
||||
|
@ -18,7 +18,7 @@ M3UParser::M3UParser()
|
||||
NonnullOwnPtr<M3UParser> M3UParser::from_file(StringView path)
|
||||
{
|
||||
auto file_result = Core::Stream::File::open(path, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
|
||||
auto contents = file_result->read_all().release_value_but_fixme_should_propagate_errors();
|
||||
auto contents = file_result->read_until_eof().release_value_but_fixme_should_propagate_errors();
|
||||
auto use_utf8 = path.ends_with(".m3u8"sv, CaseSensitivity::CaseInsensitive);
|
||||
return from_memory(DeprecatedString { contents, NoChomp }, use_utf8);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ static ErrorOr<void> fill_mounts(Vector<MountInfo>& output)
|
||||
// Output info about currently mounted filesystems.
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/df"sv, Core::Stream::OpenMode::Read));
|
||||
|
||||
auto content = TRY(file->read_all());
|
||||
auto content = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(content));
|
||||
|
||||
TRY(json.as_array().try_for_each([&output](JsonValue const& value) -> ErrorOr<void> {
|
||||
|
@ -411,7 +411,7 @@ Vector<GUI::ModelIndex> ProcessModel::matches(StringView searching, unsigned fla
|
||||
static ErrorOr<DeprecatedString> try_read_command_line(pid_t pid)
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open(DeprecatedString::formatted("/proc/{}/cmdline", pid), Core::Stream::OpenMode::Read));
|
||||
auto data = TRY(file->read_all());
|
||||
auto data = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(StringView { data.bytes() }));
|
||||
auto array = json.as_array().values();
|
||||
return DeprecatedString::join(" "sv, array);
|
||||
|
@ -238,7 +238,7 @@ ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
|
||||
auto json = JsonValue::from_string(TRY(file->read_all()));
|
||||
auto json = JsonValue::from_string(TRY(file->read_until_eof()));
|
||||
if (json.is_error() || !json.value().is_object())
|
||||
return Error::from_string_literal("Invalid perfcore format (not a JSON object)");
|
||||
|
||||
|
@ -29,7 +29,7 @@ void ScriptEditor::new_script_with_temp_name(DeprecatedString name)
|
||||
ErrorOr<void> ScriptEditor::open_script_from_file(LexicalPath const& file_path)
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open(file_path.string(), Core::Stream::OpenMode::Read));
|
||||
auto buffer = TRY(file->read_all());
|
||||
auto buffer = TRY(file->read_until_eof());
|
||||
|
||||
set_text({ buffer.bytes() });
|
||||
m_path = file_path.string();
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -86,7 +86,7 @@ static Optional<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Depre
|
||||
auto bufstream = bufstream_result.release_value();
|
||||
auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream };
|
||||
|
||||
auto uncompressed = brotli_stream.read_all();
|
||||
auto uncompressed = brotli_stream.read_until_eof();
|
||||
if (uncompressed.is_error()) {
|
||||
dbgln("Job::handle_content_encoding: Brotli::decompress() failed: {}.", uncompressed.error());
|
||||
return {};
|
||||
|
@ -104,7 +104,7 @@ static ErrorOr<bool> should_launch_server(DeprecatedString const& pid_path)
|
||||
return server_pid_file.release_error();
|
||||
}
|
||||
|
||||
auto contents = server_pid_file.value()->read_all();
|
||||
auto contents = server_pid_file.value()->read_until_eof();
|
||||
if (contents.is_error()) {
|
||||
warnln("Could not read SQLServer PID file '{}': {}", pid_path, contents.error());
|
||||
return contents.release_error();
|
||||
|
@ -243,7 +243,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
|
||||
}
|
||||
|
||||
auto file = maybe_file.release_value();
|
||||
auto maybe_data = file->read_all();
|
||||
auto maybe_data = file->read_until_eof();
|
||||
if (maybe_data.is_error()) {
|
||||
log_failure(request, maybe_data.error());
|
||||
if (error_callback)
|
||||
|
@ -29,7 +29,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
auto config_file = TRY(Core::ConfigFile::open_for_system("Network"));
|
||||
|
||||
auto proc_net_adapters_file = TRY(Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read));
|
||||
auto data = TRY(proc_net_adapters_file->read_all());
|
||||
auto data = TRY(proc_net_adapters_file->read_until_eof());
|
||||
JsonParser parser(data);
|
||||
JsonValue proc_net_adapters_json = TRY(parser.parse());
|
||||
|
||||
|
@ -90,7 +90,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
if (!flag_set && !flag_delete) {
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/net/arp"sv, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
Vector<JsonValue> sorted_regions = json.as_array().values();
|
||||
|
@ -23,7 +23,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto file = TRY(Core::Stream::File::open_file_or_standard_stream(filepath, Core::Stream::OpenMode::Read));
|
||||
ByteBuffer buffer = TRY(file->read_all());
|
||||
ByteBuffer buffer = TRY(file->read_until_eof());
|
||||
|
||||
TRY(Core::System::pledge("stdio"));
|
||||
|
||||
|
@ -43,7 +43,7 @@ static ErrorOr<Options> parse_options(Main::Arguments arguments)
|
||||
} else if (text.is_empty()) {
|
||||
// Copy our stdin.
|
||||
auto c_stdin = TRY(Core::Stream::File::standard_input());
|
||||
auto buffer = TRY(c_stdin->read_all());
|
||||
auto buffer = TRY(c_stdin->read_until_eof());
|
||||
dbgln("Read size {}", buffer.size());
|
||||
dbgln("Read data: `{}`", StringView(buffer.bytes()));
|
||||
options.data = buffer.bytes();
|
||||
|
@ -18,7 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto content = TRY(file->read_all());
|
||||
auto content = TRY(file->read_until_eof());
|
||||
StringView content_view(content);
|
||||
|
||||
Cpp::Lexer lexer(content);
|
||||
|
@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
if (path.is_empty())
|
||||
path = "Source/little/main.cpp"sv;
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto content = TRY(file->read_all());
|
||||
auto content = TRY(file->read_until_eof());
|
||||
StringView content_view(content);
|
||||
|
||||
::Cpp::Preprocessor processor(path, content_view);
|
||||
|
@ -20,7 +20,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto content = TRY(file->read_all());
|
||||
auto content = TRY(file->read_until_eof());
|
||||
DeprecatedString name = LexicalPath::basename(path);
|
||||
Cpp::Preprocessor cpp(name, StringView { content });
|
||||
auto tokens = cpp.process_and_lex();
|
||||
|
@ -40,7 +40,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
outln("Filesystem Blocks Used Available Mount point");
|
||||
}
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json_result = TRY(JsonValue::from_string(file_contents));
|
||||
auto const& json = json_result.as_array();
|
||||
json.for_each([](auto& value) {
|
||||
|
@ -28,7 +28,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
bool color_output = TRY(Core::System::isatty(STDOUT_FILENO));
|
||||
|
||||
auto hunks = Diff::from_text(TRY(file1->read_all()), TRY(file2->read_all()));
|
||||
auto hunks = Diff::from_text(TRY(file1->read_until_eof()), TRY(file2->read_until_eof()));
|
||||
for (auto const& hunk : hunks) {
|
||||
auto original_start = hunk.original_start_line;
|
||||
auto target_start = hunk.target_start_line;
|
||||
|
@ -15,7 +15,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/dmesg"sv, Core::Stream::OpenMode::Read));
|
||||
auto buffer = TRY(file->read_all());
|
||||
auto buffer = TRY(file->read_until_eof());
|
||||
out("{}", StringView { buffer });
|
||||
return 0;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ ErrorOr<void> parse_args(Main::Arguments arguments, Vector<DeprecatedString>& fi
|
||||
du_option.excluded_patterns.append(pattern);
|
||||
if (!exclude_from.is_empty()) {
|
||||
auto file = TRY(Core::Stream::File::open(exclude_from, Core::Stream::OpenMode::Read));
|
||||
auto const buff = TRY(file->read_all());
|
||||
auto const buff = TRY(file->read_until_eof());
|
||||
if (!buff.is_empty()) {
|
||||
DeprecatedString patterns = DeprecatedString::copy(buff, Chomp);
|
||||
du_option.excluded_patterns.extend(patterns.split('\n'));
|
||||
|
@ -87,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
TRY(Core::System::unveil("/etc/timezone", "r"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
if (!json.is_array()) {
|
||||
warnln("{} does not contain an array of quotes", path);
|
||||
|
@ -16,7 +16,7 @@ static ErrorOr<bool> format_file(StringView path, bool inplace)
|
||||
auto open_mode = (inplace && !read_from_stdin) ? Core::Stream::OpenMode::ReadWrite : Core::Stream::OpenMode::Read;
|
||||
auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, open_mode));
|
||||
|
||||
auto contents = TRY(file->read_all());
|
||||
auto contents = TRY(file->read_until_eof());
|
||||
auto formatted_gml_or_error = GUI::GML::format_gml(contents);
|
||||
if (formatted_gml_or_error.is_error()) {
|
||||
warnln("Failed to parse GML: {}", formatted_gml_or_error.error());
|
||||
|
@ -45,7 +45,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
TRY(Core::System::pledge("stdio"));
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
if (use_color) {
|
||||
|
@ -32,7 +32,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
if (value_ipv4.is_empty() && value_adapter.is_empty() && value_mask.is_empty()) {
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/net/adapters"sv, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
json.as_array().for_each([](auto& value) {
|
||||
|
@ -370,7 +370,7 @@ static JS::ThrowCompletionOr<JS::Value> load_json_impl(JS::VM& vm)
|
||||
if (file_or_error.is_error())
|
||||
return vm.throw_completion<JS::Error>(DeprecatedString::formatted("Failed to open '{}': {}", filename, file_or_error.error()));
|
||||
|
||||
auto file_contents_or_error = file_or_error.value()->read_all();
|
||||
auto file_contents_or_error = file_or_error.value()->read_until_eof();
|
||||
if (file_contents_or_error.is_error())
|
||||
return vm.throw_completion<JS::Error>(DeprecatedString::formatted("Failed to read '{}': {}", filename, file_contents_or_error.error()));
|
||||
|
||||
@ -878,7 +878,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
for (auto& path : script_paths) {
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto source = StringView { file_contents };
|
||||
|
||||
if (Utf8View { file_contents }.validate()) {
|
||||
|
@ -47,7 +47,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
TRY(Core::System::pledge("stdio"));
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
if (!dotted_key.is_empty()) {
|
||||
auto key_parts = dotted_key.split_view('.');
|
||||
|
@ -56,21 +56,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
continue;
|
||||
}
|
||||
|
||||
auto maybe_command_set = command_set_file.value()->read_all();
|
||||
auto maybe_command_set = command_set_file.value()->read_until_eof();
|
||||
if (maybe_command_set.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", command_set_filename, maybe_command_set.error());
|
||||
continue;
|
||||
}
|
||||
DeprecatedString command_set = StringView(maybe_command_set.value().bytes());
|
||||
|
||||
auto maybe_last_lba = last_lba_file.value()->read_all();
|
||||
auto maybe_last_lba = last_lba_file.value()->read_until_eof();
|
||||
if (maybe_last_lba.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", last_lba_filename, maybe_last_lba.error());
|
||||
continue;
|
||||
}
|
||||
DeprecatedString last_lba = StringView(maybe_last_lba.value().bytes());
|
||||
|
||||
auto maybe_sector_size = sector_size_file.value()->read_all();
|
||||
auto maybe_sector_size = sector_size_file.value()->read_until_eof();
|
||||
if (maybe_sector_size.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", sector_size_filename, maybe_sector_size.error());
|
||||
continue;
|
||||
|
@ -60,7 +60,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/cpuinfo"sv, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
auto const& array = json.as_array();
|
||||
|
||||
|
@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
|
||||
TRY(Core::System::pledge("stdio"));
|
||||
|
||||
auto file_contents = TRY(proc_interrupts->read_all());
|
||||
auto file_contents = TRY(proc_interrupts->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
auto cpu_count = json.as_array().at(0).as_object().get("per_cpu_call_counts"sv).as_array().size();
|
||||
|
@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
TRY(Core::System::pledge("stdio"));
|
||||
|
||||
outln("Index Name");
|
||||
auto file_contents = TRY(jails_data->read_all());
|
||||
auto file_contents = TRY(jails_data->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
json.as_array().for_each([](auto& value) {
|
||||
auto& jail = value.as_object();
|
||||
|
@ -70,7 +70,7 @@ static Vector<OpenFile> get_open_files_by_pid(pid_t pid)
|
||||
outln("lsof: PID {}: {}", pid, file.error());
|
||||
return Vector<OpenFile>();
|
||||
}
|
||||
auto data = file.value()->read_all();
|
||||
auto data = file.value()->read_until_eof();
|
||||
if (data.is_error()) {
|
||||
outln("lsof: PID {}: {}", pid, data.error());
|
||||
return {};
|
||||
|
@ -119,35 +119,35 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
continue;
|
||||
}
|
||||
|
||||
auto vendor_id_contents = vendor_id_file.value()->read_all();
|
||||
auto vendor_id_contents = vendor_id_file.value()->read_until_eof();
|
||||
if (vendor_id_contents.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", vendor_id_filename, vendor_id_contents.error());
|
||||
continue;
|
||||
}
|
||||
u32 vendor_id = read_hex_string_from_bytebuffer(vendor_id_contents.value());
|
||||
|
||||
auto device_id_contents = device_id_file.value()->read_all();
|
||||
auto device_id_contents = device_id_file.value()->read_until_eof();
|
||||
if (device_id_contents.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", device_id_filename, device_id_contents.error());
|
||||
continue;
|
||||
}
|
||||
u32 device_id = read_hex_string_from_bytebuffer(device_id_contents.value());
|
||||
|
||||
auto revision_id_contents = revision_id_file.value()->read_all();
|
||||
auto revision_id_contents = revision_id_file.value()->read_until_eof();
|
||||
if (revision_id_contents.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", revision_id_filename, revision_id_contents.error());
|
||||
continue;
|
||||
}
|
||||
u32 revision_id = read_hex_string_from_bytebuffer(revision_id_contents.value());
|
||||
|
||||
auto class_id_contents = class_id_file.value()->read_all();
|
||||
auto class_id_contents = class_id_file.value()->read_until_eof();
|
||||
if (class_id_contents.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", class_id_filename, class_id_contents.error());
|
||||
continue;
|
||||
}
|
||||
u32 class_id = read_hex_string_from_bytebuffer(class_id_contents.value());
|
||||
|
||||
auto subclass_id_contents = subclass_id_file.value()->read_all();
|
||||
auto subclass_id_contents = subclass_id_file.value()->read_until_eof();
|
||||
if (subclass_id_contents.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", subclass_id_filename, subclass_id_contents.error());
|
||||
continue;
|
||||
@ -183,7 +183,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
continue;
|
||||
}
|
||||
|
||||
auto bar_value_contents = bar_value_file.value()->read_all();
|
||||
auto bar_value_contents = bar_value_file.value()->read_until_eof();
|
||||
if (bar_value_contents.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", bar_value_filename, bar_value_contents.error());
|
||||
continue;
|
||||
|
@ -54,7 +54,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
continue;
|
||||
}
|
||||
|
||||
auto contents = proc_usb_device.value()->read_all();
|
||||
auto contents = proc_usb_device.value()->read_until_eof();
|
||||
if (contents.is_error()) {
|
||||
warnln("Failed to read {}: {}", full_path.string(), contents.error());
|
||||
continue;
|
||||
|
@ -90,7 +90,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
TRY(Core::System::pledge("stdio proc"));
|
||||
|
||||
dbgln("Loading man page from {}", TRY(page->path()));
|
||||
auto buffer = TRY(file->read_all());
|
||||
auto buffer = TRY(file->read_until_eof());
|
||||
auto source = DeprecatedString::copy(buffer);
|
||||
|
||||
auto const title = TRY(String::from_utf8("SerenityOS manual"sv));
|
||||
|
@ -242,7 +242,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
}
|
||||
auto file = file_or_error.release_value();
|
||||
|
||||
auto content_buffer_or_error = file->read_all();
|
||||
auto content_buffer_or_error = file->read_until_eof();
|
||||
if (content_buffer_or_error.is_error()) {
|
||||
warnln("Failed to read {}: {}", path, file_or_error.error());
|
||||
// Since this should never happen anyway, fail early.
|
||||
|
@ -45,7 +45,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
TRY(Core::System::pledge("stdio"));
|
||||
|
||||
auto buffer = TRY(file->read_all());
|
||||
auto buffer = TRY(file->read_until_eof());
|
||||
dbgln("Read size {}", buffer.size());
|
||||
|
||||
auto input = DeprecatedString::copy(buffer);
|
||||
|
@ -150,7 +150,7 @@ static ErrorOr<void> print_mounts()
|
||||
// Output info about currently mounted filesystems.
|
||||
auto df = TRY(Core::Stream::File::open("/sys/kernel/df"sv, Core::Stream::OpenMode::Read));
|
||||
|
||||
auto content = TRY(df->read_all());
|
||||
auto content = TRY(df->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(content));
|
||||
|
||||
json.as_array().for_each([](auto& value) {
|
||||
|
@ -153,7 +153,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
if (!has_protocol_flag || flag_tcp) {
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/net/tcp"sv, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json_or_error = JsonValue::from_string(file_contents);
|
||||
if (json_or_error.is_error()) {
|
||||
warnln("Error: {}", json_or_error.error());
|
||||
@ -245,7 +245,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
if (!has_protocol_flag || flag_udp) {
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/net/udp"sv, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
Vector<JsonValue> sorted_regions = json.as_array().values();
|
||||
|
@ -17,7 +17,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
if (file_or_error.is_error()) {
|
||||
outln("This account is currently not available.");
|
||||
} else {
|
||||
auto message_from_file = TRY(file_or_error.value()->read_all());
|
||||
auto message_from_file = TRY(file_or_error.value()->read_until_eof());
|
||||
out("{}", StringView { message_from_file });
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
TRY(Core::System::pledge("stdio rpath"));
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/cpuinfo"sv, Core::Stream::OpenMode::Read));
|
||||
|
||||
auto buffer = TRY(file->read_all());
|
||||
auto buffer = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(buffer));
|
||||
auto const& cpuinfo_array = json.as_array();
|
||||
outln("{}", cpuinfo_array.size());
|
||||
|
@ -42,7 +42,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
outln("Address{} Size Access Name", padding);
|
||||
}
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
Vector<JsonValue> sorted_regions = json.as_array().values();
|
||||
|
@ -90,7 +90,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
if (modify_action.is_empty()) {
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/net/route"sv, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
outln("Kernel IP routing table");
|
||||
|
@ -30,7 +30,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto file = TRY(Core::Stream::File::open_file_or_standard_stream(path, Core::Stream::OpenMode::Read));
|
||||
ByteBuffer buffer = TRY(file->read_all());
|
||||
ByteBuffer buffer = TRY(file->read_until_eof());
|
||||
|
||||
u8 input_delimiter = is_zero_terminated ? '\0' : '\n';
|
||||
Vector<Bytes> lines;
|
||||
|
@ -20,7 +20,7 @@ static DeprecatedString get_variable(StringView name)
|
||||
warnln("Failed to open {}: {}", path, file.error());
|
||||
return {};
|
||||
}
|
||||
auto buffer = file.value()->read_all();
|
||||
auto buffer = file.value()->read_until_eof();
|
||||
if (buffer.is_error()) {
|
||||
warnln("Failed to read {}: {}", path, buffer.error());
|
||||
return {};
|
||||
|
@ -15,7 +15,7 @@
|
||||
static ErrorOr<void> tail_from_pos(Core::Stream::File& file, off_t startline)
|
||||
{
|
||||
TRY(file.seek(startline + 1, Core::Stream::SeekMode::SetPosition));
|
||||
auto buffer = TRY(file.read_all());
|
||||
auto buffer = TRY(file.read_until_eof());
|
||||
out("{}", StringView { buffer });
|
||||
return {};
|
||||
}
|
||||
@ -70,7 +70,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
do {
|
||||
// FIXME: If f is the standard input, f->read_all() does not block
|
||||
// anymore after sending EOF (^D), despite f->is_open() returning true.
|
||||
auto buffer = TRY(f->read_all(PAGE_SIZE));
|
||||
auto buffer = TRY(f->read_until_eof(PAGE_SIZE));
|
||||
auto line_count = StringView(buffer).count("\n"sv);
|
||||
auto bytes = buffer.bytes();
|
||||
size_t line_index = 0;
|
||||
@ -108,7 +108,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
auto watcher = TRY(Core::FileWatcher::create());
|
||||
watcher->on_change = [&](Core::FileWatcherEvent const& event) {
|
||||
if (event.type == Core::FileWatcherEvent::Type::ContentModified) {
|
||||
auto buffer_or_error = f->read_all();
|
||||
auto buffer_or_error = f->read_until_eof();
|
||||
if (buffer_or_error.is_error()) {
|
||||
auto error = buffer_or_error.error();
|
||||
warnln(error.string_literal());
|
||||
|
@ -152,7 +152,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
auto fn = parse_target_name(type);
|
||||
|
||||
auto file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Read));
|
||||
auto input = TRY(file->read_all());
|
||||
auto input = TRY(file->read_until_eof());
|
||||
|
||||
return fn(input.data(), input.size());
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::ReadWrite));
|
||||
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto previous_json = TRY(JsonValue::from_string(file_contents));
|
||||
|
||||
JsonObject json;
|
||||
|
@ -26,7 +26,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::Read));
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
if (!json.is_object()) {
|
||||
warnln("Error: Could not parse /var/run/utmp");
|
||||
|
@ -372,7 +372,7 @@ static auto parse(StringView contents)
|
||||
return Error::from_string_literal("NYI: Nonlocal entity");
|
||||
|
||||
auto file = TRY(Core::Stream::File::open(url.path(), Core::Stream::OpenMode::Read));
|
||||
return DeprecatedString::copy(TRY(file->read_all()));
|
||||
return DeprecatedString::copy(TRY(file->read_until_eof()));
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -449,7 +449,7 @@ static void do_run_tests(XML::Document& document)
|
||||
|
||||
warnln("Running test {}", url.path());
|
||||
|
||||
auto contents = file_result.value()->read_all();
|
||||
auto contents = file_result.value()->read_until_eof();
|
||||
if (contents.is_error()) {
|
||||
warnln("Read error for {}: {}", url.path(), contents.error());
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
@ -474,7 +474,7 @@ static void do_run_tests(XML::Document& document)
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
continue;
|
||||
}
|
||||
auto contents = file_result.value()->read_all();
|
||||
auto contents = file_result.value()->read_until_eof();
|
||||
if (contents.is_error()) {
|
||||
warnln("Read error for {}: {}", out_path, contents.error());
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
@ -517,7 +517,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
s_path = Core::File::real_path_for(filename);
|
||||
auto file = TRY(Core::Stream::File::open(s_path, Core::Stream::OpenMode::Read));
|
||||
auto contents = TRY(file->read_all());
|
||||
auto contents = TRY(file->read_until_eof());
|
||||
|
||||
auto xml_parser = parse(contents);
|
||||
auto result = xml_parser.parse();
|
||||
|
Loading…
Reference in New Issue
Block a user