Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions cppwinrt/text_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ namespace cppwinrt
{
inline std::string file_to_string(std::string const& filename)
{
std::ifstream file(filename, std::ios::binary);
return static_cast<std::stringstream const&>(std::stringstream() << file.rdbuf()).str();
std::ifstream file(filename, std::ios::binary | std::ios::ate);
const auto size = file.tellg();
file.seekg(0);
std::string result(size, '\0');
file.read(result.data(), size);
return result;
Comment thread
DefaultRyan marked this conversation as resolved.
}

template <typename T>
Expand Down Expand Up @@ -218,18 +222,13 @@ namespace cppwinrt

bool file_equal(std::string const& filename) const
{
if (!std::filesystem::exists(filename))
if (!std::filesystem::exists(filename) || std::filesystem::file_size(filename) != m_first.size() + m_second.size())
{
return false;
Comment thread
DefaultRyan marked this conversation as resolved.
Outdated
}

auto file = file_to_string(filename);

if (file.size() != m_first.size() + m_second.size())
{
return false;
}

if (!std::equal(m_first.begin(), m_first.end(), file.begin(), file.begin() + m_first.size()))
{
return false;
Expand Down
Loading