diff --git a/src/lib/file.cpp b/src/lib/file.cpp index 4794fd6..216077f 100644 --- a/src/lib/file.cpp +++ b/src/lib/file.cpp @@ -61,10 +61,6 @@ bool File::eof() { } ErrorOr File::readByte(){ - uint8_t* nextPointer = new uint8_t; - uint8_t nextByte; - bool failure = false; - if (!this->isOpen) { return ErrorOr(true, ErrorCodes::FILE_NOT_OPEN); } @@ -72,6 +68,10 @@ ErrorOr File::readByte(){ return ErrorOr(true, ErrorCodes::OVERRUN); } + uint8_t* nextPointer = new uint8_t; + uint8_t nextByte; + bool failure = false; + try { this->fileStream.seekg(this->cursorPosition); this->fileStream.read(reinterpret_cast(nextPointer), 1); @@ -87,10 +87,6 @@ ErrorOr File::readByte(){ } ErrorOr> File::read(uint64_t bytes){ - uint8_t* buffer = new uint8_t[bytes]; - std::vector data; - bool failure = false; - if (!this->isOpen) { return ErrorOr>(true, ErrorCodes::FILE_NOT_OPEN); } @@ -98,6 +94,10 @@ ErrorOr> File::read(uint64_t bytes){ return ErrorOr>(true, ErrorCodes::OVERRUN); } + uint8_t* buffer = new uint8_t[bytes]; + std::vector data; + bool failure = false; + try { this->fileStream.seekg(this->cursorPosition); this->fileStream.read(reinterpret_cast(buffer), bytes);