MCPcopy Create free account
hub / github.com/XorTroll/Goldleaf / IsFileBinary

Method IsFileBinary

Goldleaf/source/fs/fs_Explorer.cpp:191–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189 }
190
191 bool Explorer::IsFileBinary(const std::string &path) {
192 const auto full_path = this->MakeFull(path);
193 if(!this->IsFile(full_path)) {
194 return false;
195 }
196 const auto file_size = this->GetFileSize(full_path);
197 if(file_size == 0) {
198 return true;
199 }
200
201 const auto to_read_size = std::min(file_size, BinaryCheckWorkBufferSize);
202 const auto read_size = this->ReadFile(full_path, 0, to_read_size, g_BinaryCheckWorkBuffer);
203 if(read_size == 0) {
204 return true;
205 }
206 else {
207 for(u32 i = 0; i < read_size; i++) {
208 const auto cur_ch = static_cast<char>(g_BinaryCheckWorkBuffer[i]);
209 if(!IsCharacterText(cur_ch)) {
210 return true;
211 }
212 }
213 return false;
214 }
215 }
216
217 std::vector<u8> Explorer::ReadFile(const std::string &path) {
218 const auto full_path = this->MakeFull(path);

Callers 1

OnFileSelectedMethod · 0.80

Calls 5

MakeFullMethod · 0.95
ReadFileMethod · 0.95
IsCharacterTextFunction · 0.85
IsFileMethod · 0.45
GetFileSizeMethod · 0.45

Tested by

no test coverage detected