-
Notifications
You must be signed in to change notification settings - Fork 1
[BALDE-10] Implement big file reader for Windows. #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| namespace Bald::Utils { | ||
|
|
||
| std::string FileManager::ReadFile(const char* filePath, Size size) { | ||
| if (size == Size::SMALL_FILE) | ||
| if (size == Size::small_file) | ||
| return ReadSmallFile(filePath); | ||
| return ReadBigFile(filePath); | ||
| } | ||
|
|
@@ -74,10 +74,32 @@ namespace Bald::Utils { | |
| return result; | ||
| } | ||
|
|
||
| #elif WINDOWS | ||
| #else | ||
| #include <fstream> | ||
| std::string FileManager::ReadBigFile(const char *filePath) { | ||
| CORE_LOG_INFO("[FILE_MANAGER] Error: Windows implementation is not done yet! Using slower reading method!"); | ||
| ReadSmallFile(filePath); | ||
| // CORE_LOG_INFO("[FILE_MANAGER] Error: Windows implementation is not done yet! Using slower reading method!"); | ||
| // ReadSmallFile(filePath); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comments |
||
| std::streampos begin,end; | ||
| std::ifstream file(filePath, std::ios::in); | ||
| char* buffer; | ||
| if(file.is_open()){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you do some research on the performance of this code? |
||
| begin = file.tellg(); | ||
| file.seekg (0, std::ios::end); | ||
| end = file.tellg(); | ||
| auto size = static_cast<size_t>(end-begin); | ||
| buffer = new char[static_cast<unsigned long>(size)]; | ||
| std::memset(buffer, '\0', static_cast<unsigned long>(size)); | ||
| file.seekg(0, std::ios::beg); | ||
| file.read(buffer, static_cast<std::streamsize>(size)); | ||
| file.close(); | ||
| std::string result(buffer); | ||
| delete[] buffer; | ||
| return result; | ||
| } | ||
|
|
||
| CORE_LOG_WARN("[FileManager] Couldn't get size of the file. Check if the file exists at path: " + static_cast<std::string>(filePath)); | ||
| return "[FileManager] Couldn't get size of the file. Check if the file exists at path: " + static_cast<std::string>(filePath); | ||
|
|
||
| } | ||
| #endif | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ namespace Bald::Utils { | |
| * ENUM which determines size of file and therefor methods, which will be used to read it | ||
| */ | ||
| enum class Size : char { | ||
| SMALL_FILE, BIG_FILE | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to have fixed convention for enum naming
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
| small_file, big_file | ||
| }; | ||
| public: | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add ${CMAKE_CURRENT_SOURCE_DIR}/