MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / read_binary_blob

Function read_binary_blob

src/framework/io/binary.cpp:128–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126#elif defined(_WIN32)
127 if (mapped_ != nullptr) {
128 UnmapViewOfFile(mapped_);
129 mapped_ = nullptr;
130 size_ = 0;
131 }
132#else
133 mapped_ = nullptr;
134 size_ = 0;
135#endif
136 owned_.clear();
137 owned_.shrink_to_fit();
138}
139
140BinaryBlob read_binary_blob(const std::filesystem::path & path) {
141#if defined(__unix__) || defined(__APPLE__)
142 const int fd = open(path.c_str(), O_RDONLY);
143 if (fd >= 0) {
144 struct stat st {};
145 if (fstat(fd, &st) == 0 && st.st_size >= 0) {
146 const size_t size = static_cast<size_t>(st.st_size);
147 if (size == 0) {
148 close(fd);
149 return BinaryBlob();
150 }
151 void * mapped = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0);
152 close(fd);
153 if (mapped != MAP_FAILED) {
154 return BinaryBlob(static_cast<const std::byte *>(mapped), size);
155 }
156 } else {
157 close(fd);
158 }
159 }
160#elif defined(_WIN32)
161 const HANDLE file = CreateFileW(
162 path.c_str(),
163 GENERIC_READ,
164 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
165 nullptr,
166 OPEN_EXISTING,
167 FILE_ATTRIBUTE_NORMAL,

Callers 4

SafeTensorSourceMethod · 0.85
require_data_rangeMethod · 0.85
read_binary_fileFunction · 0.85
load_voice_state_assetsFunction · 0.85

Calls 3

BinaryBlobClass · 0.85
readMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected