Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline bool FileLoader::readBytes(unsigned char* buffer, unsigned int size, long pos)
- {
- if(m_use_cache){
- //seek at pos
- unsigned long reading, remain = size, bufferPos = 0;
- do{
- //prepare cache
- unsigned long i = getCacheBlock(pos);
- if(i == NO_VALID_CACHE)
- return false;
- m_cache_index = i;
- m_cache_offset = pos - m_cached_data[i].base;
- //get maximun read block size and calculate remaining bytes
- reading = std::min(remain, m_cached_data[i].size - m_cache_offset);
- remain = remain - reading;
- //read it
- memcpy(buffer + bufferPos, m_cached_data[m_cache_index].data + m_cache_offset, reading);
- //update variables
- m_cache_offset = m_cache_offset + reading;
- bufferPos = bufferPos + reading;
- pos = pos + reading;
- }while(remain > 0);
- return true;
- }
- else{
- if(fseek(m_file, pos, SEEK_SET)){
- m_lastError = ERROR_SEEK_ERROR;
- return false;
- }
- size_t value = fread(buffer, 1, size, m_file);
- if(value != size){
- m_lastError = ERROR_EOF;
- return false;
- }
- else{
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement