diff --git a/src/fileReader.c b/src/fileReader.c index 9906853..582d998 100644 --- a/src/fileReader.c +++ b/src/fileReader.c @@ -33,7 +33,7 @@ void initFileReader(char path[], unsigned long offset) { //Reads the given amount of bytes from the file and writes them into the given buffer. Automatically opens next file if EOF is reached. -void getBytes(uint8_t* buffer, unsigned long numBytes) { +void getBytes(uint8_t* buffer, unsigned long numBytes, bool isLast) { uint8_t* bufferPosition = buffer; unsigned long remainingBytes = numBytes; @@ -52,7 +52,8 @@ void getBytes(uint8_t* buffer, unsigned long numBytes) { remainingBytes -= availableBytes; //If we've reached end of file, close file and open next file - if (file.offset == file.size) { + //Unless we've reached the end, in that case don't open next file in case we've reached the end of the last disk + if (!isLast && file.offset == file.size) { openNextFile(); } } diff --git a/src/fileReader.h b/src/fileReader.h index fdf15bb..d8300fa 100644 --- a/src/fileReader.h +++ b/src/fileReader.h @@ -4,4 +4,4 @@ void initFileReader(char path[], unsigned long offset); -void getBytes(uint8_t* buffer, unsigned long numBytes); +void getBytes(uint8_t* buffer, unsigned long numBytes, bool isLast); diff --git a/src/main.c b/src/main.c index eff7cf8..fcfc73c 100644 --- a/src/main.c +++ b/src/main.c @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) { while (remainingBytes > 0 || !hasReachedEnd) { if (needToRead) { chunkSize = min(BUFFER_SIZE - uncompressedPosition, remainingBytes); - getBytes(compressedChunk, chunkSize); + getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes); remainingBytes -= chunkSize; //Decrypt file if it is encrypted