Remove string from buffer

This commit is contained in:
Nikola Petrov 2024-08-12 21:43:12 +02:00
parent aaf5e45824
commit 2f4ad253a1
2 changed files with 4 additions and 20 deletions

View File

@ -11,7 +11,6 @@ public:
uint8_t *buffer = nullptr; uint8_t *buffer = nullptr;
size_t taken = 0; size_t taken = 0;
size_t size = 0; size_t size = 0;
std::string file_path;
Buffer(size_t size); Buffer(size_t size);
Buffer(); Buffer();
@ -31,10 +30,7 @@ public:
void clear() { taken = 0; } void clear() { taken = 0; }
bool save_to_file();
bool save_to_file(std::string file_path); bool save_to_file(std::string file_path);
bool load_from_file();
bool load_from_file(std::string file_path); bool load_from_file(std::string file_path);
}; };

View File

@ -103,9 +103,9 @@ void Buffer::remove(uint8_t *data, size_t data_size)
remove(index, data_size); remove(index, data_size);
} }
bool Buffer::save_to_file() bool Buffer::save_to_file(std::string file_path)
{ {
std::ofstream file(this->file_path, std::ios::binary | std::ios::out); std::ofstream file(file_path, std::ios::binary | std::ios::out);
if (!file.is_open()) if (!file.is_open())
{ {
printf("Error saving file\n"); printf("Error saving file\n");
@ -116,15 +116,9 @@ bool Buffer::save_to_file()
return true; return true;
} }
bool Buffer::save_to_file(std::string file_path) bool Buffer::load_from_file(std::string file_path)
{ {
this->file_path = file_path; std::ifstream file(file_path, std::ios::binary | std::ios::in);
return save_to_file();
}
bool Buffer::load_from_file()
{
std::ifstream file(this->file_path, std::ios::binary | std::ios::in);
if (!file.is_open()) if (!file.is_open())
return false; return false;
@ -144,9 +138,3 @@ bool Buffer::load_from_file()
file.close(); file.close();
return true; return true;
} }
bool Buffer::load_from_file(std::string file_path)
{
this->file_path = file_path;
return load_from_file();
}