-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandler.cpp
More file actions
41 lines (34 loc) · 1.02 KB
/
FileHandler.cpp
File metadata and controls
41 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Created by hmaurya on 20/02/20.
//
#include "FileHandler.h"
void FileHandler::initializeFile(string newFilename) {
if (this->fileOutStream.is_open()) {
this->fileOutStream.close();
}
this->filename = std::move(newFilename);
this->fileOutStream.open(this->filename, ios_base::binary);
}
void FileHandler::writeByte(char toWrite) {
int buf_size = 1;
char* buffer = new char[buf_size];
buffer[0] = toWrite;
fileOutStream.write(buffer, buf_size);
delete [] buffer;
}
void FileHandler::writeString(const string& toWrite) {
fileOutStream << toWrite;
}
int FileHandler::currentSize() {
unsigned int currentFilePosition = this->fileOutStream.tellp();
this->fileOutStream.seekp(0, ios::end);
int fileSize = this->fileOutStream.tellp();
this->fileOutStream.seekp(currentFilePosition, ios::beg);
return fileSize;
}
unsigned int FileHandler::currentWriteHeadPosition() {
return this->fileOutStream.tellp();
}
void FileHandler::close() {
this->fileOutStream.close();
}