I have the following problem:
I got a file in a binary format, which is stored in the assets directory of my app. And I want to read this file and write it's contents to another place. The logic for reading and writing works fine for "normal" text files, but for the binary file I get weird and unintended behaviour. If i read a text file, my filecontent and buffer stores the text just fine. For a binary file the buffer is mostly empty and missing a lot of the data. And I am also not able to write the contents from the buffer to the filecontent array. This is the code for reading the files:
AAsset* file = AAssetManager_open(Application::AssetManager,
filePath.c_str(), AASSET_MODE_BUFFER);
long fileLength = AAsset_getLength(file);
unsigned char* fileContent = new unsigned char[fileLength];
int currentByte = 0;
//256 kb chunk size
const int BUFFER_SIZE = 1024*256;
unsigned char buffer[BUFFER_SIZE];
while(true){
int bytesRead = AAsset_read(file, buffer, BUFFER_SIZE);
if(bytesRead <= 0){
break;
}
for(int i=0; i < bytesRead; i++){
fileContent[currentByte] = buffer[i];
currentByte++;
}
}
Is there anything obvious I am missing? Or do I need to use different datatypes for the binary data? Any tips are appreciated :)