Skip to content

[k2] support file_get_contents#1592

Open
Shamzik wants to merge 7 commits intomasterfrom
kshamazov/file_get_contents
Open

[k2] support file_get_contents#1592
Shamzik wants to merge 7 commits intomasterfrom
kshamazov/file_get_contents

Conversation

@Shamzik
Copy link
Copy Markdown
Contributor

@Shamzik Shamzik commented Apr 3, 2026

This PR implements file::get_contents method and enables gzip test. Implementation was got from file kphp function.

@Shamzik Shamzik self-assigned this Apr 3, 2026
@Shamzik Shamzik added runtime Feature related to runtime k2 Affects compiler or runtime in K2 mode labels Apr 3, 2026
@Shamzik Shamzik added this to the next milestone Apr 3, 2026
#include <type_traits>
#include <utility>

#include <sys/stat.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System headers should be placed in a single block

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are

@Shamzik Shamzik requested a review from apolyakov April 6, 2026 09:01

static auto create(size_t length, int32_t prot, int32_t flags, k2::descriptor fd, uint64_t offset) noexcept -> std::expected<mmap, int32_t>;

auto get_contents() noexcept -> string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mmap is not a resource we don't need to return any of kPHP types here. Thus, we can use it in more contexts, e.g. in ComponentState. What do you think about changing the signature to auto data() noexcept -> std::span<std::byte>?

return std::unexpected{k2::errno_enomem};
}

return kphp::fs::mmap::create(size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, m_descriptor, 0).transform(&kphp::fs::mmap::get_contents);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: std::addressof instead of &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

k2 Affects compiler or runtime in K2 mode runtime Feature related to runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants