Definition at line 795 of file IOBuffer.h. 00796 { 00797 // read all contents of file and put in the IOBuffer 00798 FILE* file = fopen(filename.c_str(), "r"); 00799 if (!file) 00800 { 00801 std::cout << "[CreateIOBufferFromFile] failed to open " << filename 00802 << std::endl; 00803 return 0; 00804 } 00805 00806 int blockSize = 0x1000; 00807 std::deque<unsigned char*> bufferList; 00808 int read; 00809 do 00810 { 00811 unsigned char* buffer = new unsigned char[blockSize]; 00812 read = fread(buffer,1,blockSize,file); 00813 bufferList.push_back(buffer); 00814 } 00815 while (read == blockSize); 00816 fclose(file); 00817 00818 // create total buffer 00819 int total = ((bufferList.size()-1)*blockSize) + read; 00820 unsigned char* buffer = new unsigned char[total]; 00821 int i; 00822 for(i=0 ; i<bufferList.size() - 1 ; i++) 00823 { 00824 memcpy(buffer + (i*blockSize), bufferList[i], blockSize); 00825 delete [] bufferList[i]; 00826 bufferList[i] = 0; 00827 } 00828 memcpy(buffer + (i*blockSize), bufferList[i], read); // last block only #read bytes 00829 delete [] bufferList[i]; 00830 bufferList[i] = 0; 00831 00832 return new IOBuffer(total, buffer); 00833 }
|