MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / ReadFile_Cache

Function ReadFile_Cache

src/External/CascLib/src/CascReadFile.cpp:744–772  ·  view source on GitHub ↗

Reads the file data from cache. Returns the number of bytes read

Source from the content-addressed store, hash-verified

742
743// Reads the file data from cache. Returns the number of bytes read
744static DWORD ReadFile_Cache(TCascFile * hf, LPBYTE pbBuffer, ULONGLONG StartOffset, ULONGLONG EndOffset)
745{
746 // Is there a file cache at all?
747 if(hf->pbFileCache != NULL && hf->FileCacheStart <= StartOffset && StartOffset < hf->FileCacheEnd)
748 {
749 LPBYTE pbStartBlock = hf->pbFileCache + (size_t)(StartOffset - hf->FileCacheStart);
750
751 // Can we handle the entire request from the cache?
752 if(EndOffset <= hf->FileCacheEnd)
753 {
754 DWORD dwBytesToCopy = (DWORD)(EndOffset - StartOffset);
755
756 memcpy(pbBuffer, pbStartBlock, dwBytesToCopy);
757 return dwBytesToCopy;
758 }
759
760 // We copy as much bytes as available. The rest is handled by normal read
761 else
762 {
763 DWORD dwBytesToCopy = (DWORD)(hf->FileCacheEnd - StartOffset);
764
765 memcpy(pbBuffer, pbStartBlock, dwBytesToCopy);
766 return dwBytesToCopy;
767 }
768 }
769
770 // Can't handle the request from the cache
771 return 0;
772}
773
774// No cache at all. The entire file will be read directly to the user buffer
775static DWORD ReadFile_WholeFile(TCascFile * hf, LPBYTE pbBuffer)

Callers 1

CascReadFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected