50 uint8_t, AlignedAllocator<uint8_t, 16>>>>,
55#if defined(__unix__) || defined(__APPLE__)
56 auto fclose = [](std::FILE* fp) { std::fclose(fp); };
57 using file_ptr = std::unique_ptr<FILE,
decltype(fclose)>;
58 file_ptr file(fopen(
fileName,
"rb"), fclose);
63 if (fseek(file.get(), 0, SEEK_END) == -1)
64 ThrowFIE(
"Could not rewind to the end of the file");
66 const auto size = ftell(file.get());
68 ThrowFIE(
"Could not obtain the file size");
73 if (
static_cast<int64_t
>(size) >
74 std::numeric_limits<Buffer::size_type>::max())
75 ThrowFIE(
"File is too big (%zu bytes).", fileSize);
79 if (fseek(file.get(), 0, SEEK_SET) == -1)
80 ThrowFIE(
"Could not rewind to the beginning of the file");
82 auto dest = std::make_unique<std::vector<
87 auto bytes_read = fread(dest->data(), 1, fileSize, file.get());
88 if (ferror(file.get()))
89 ThrowFIE(
"Could not read file, file reading error");
91 ThrowFIE(
"Could not read file, reached end-of-file");
92 if (fileSize != bytes_read)
93 ThrowFIE(
"Could not read file, unknown problem");
99 using file_ptr = std::unique_ptr<std::remove_pointer<HANDLE>::type,
100 decltype(&CloseHandle)>;
101 file_ptr file(CreateFileW(wFileName.data(), GENERIC_READ, FILE_SHARE_READ,
102 nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
106 if (file.get() == INVALID_HANDLE_VALUE)
110 GetFileSizeEx(file.get(), &size);
113 std::numeric_limits<Buffer::size_type>::max() ==
114 std::numeric_limits<
decltype(size.LowPart)>::max(),
115 "once Buffer migrates to 64-bit index, this needs to be updated.");
117 if (size.HighPart > 0)
119 if (size.LowPart <= 0)
122 auto dest = std::make_unique<std::vector<
128 if (!ReadFile(file.get(), dest->data(), size.LowPart, &bytes_read,
nullptr))
131 if (size.LowPart != bytes_read)
134 fileSize = size.LowPart;
138 return {std::move(dest),