MCPcopy Create free account
hub / github.com/diasurgical/devilution / FlatStream_BlockRead

Function FlatStream_BlockRead

3rdParty/StormLib/src/FileStream.cpp:1213–1255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1211}
1212
1213static bool FlatStream_BlockRead(
1214 TBlockStream * pStream, // Pointer to an open stream
1215 ULONGLONG StartOffset,
1216 ULONGLONG EndOffset,
1217 LPBYTE BlockBuffer,
1218 DWORD BytesNeeded,
1219 bool bAvailable)
1220{
1221 DWORD BytesToRead = (DWORD)(EndOffset - StartOffset);
1222
1223 // The starting offset must be aligned to size of the block
1224 assert(pStream->FileBitmap != NULL);
1225 assert((StartOffset & (pStream->BlockSize - 1)) == 0);
1226 assert(StartOffset < EndOffset);
1227
1228 // If the blocks are not available, we need to load them from the master
1229 // and then save to the mirror
1230 if(bAvailable == false)
1231 {
1232 // If we have no master, we cannot satisfy read request
1233 if(pStream->pMaster == NULL)
1234 return false;
1235
1236 // Load the blocks from the master stream
1237 // Note that we always have to read complete blocks
1238 // so they get properly stored to the mirror stream
1239 if(!FileStream_Read(pStream->pMaster, &StartOffset, BlockBuffer, BytesToRead))
1240 return false;
1241
1242 // Store the loaded blocks to the mirror file.
1243 // Note that this operation is not required to succeed
1244 if(pStream->BaseWrite(pStream, &StartOffset, BlockBuffer, BytesToRead))
1245 FlatStream_UpdateBitmap(pStream, StartOffset, EndOffset);
1246
1247 return true;
1248 }
1249 else
1250 {
1251 if(BytesToRead > BytesNeeded)
1252 BytesToRead = BytesNeeded;
1253 return pStream->BaseRead(pStream, &StartOffset, BlockBuffer, BytesToRead);
1254 }
1255}
1256
1257static void FlatStream_Close(TBlockStream * pStream)
1258{

Callers

nothing calls this directly

Calls 2

FileStream_ReadFunction · 0.85
FlatStream_UpdateBitmapFunction · 0.85

Tested by

no test coverage detected