MCPcopy Create free account
hub / github.com/ddnet/ddnet / CalculateHashes

Method CalculateHashes

src/engine/shared/storage.cpp:639–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637 }
638
639 bool CalculateHashes(const char *pFilename, int Type, SHA256_DIGEST *pSha256, unsigned *pCrc) override
640 {
641 dbg_assert(pSha256 != nullptr || pCrc != nullptr, "At least one output argument required");
642
643 IOHANDLE File = OpenFile(pFilename, IOFLAG_READ, Type);
644 if(!File)
645 return false;
646
647 SHA256_CTX Sha256Ctxt;
648 if(pSha256 != nullptr)
649 sha256_init(&Sha256Ctxt);
650 if(pCrc != nullptr)
651 *pCrc = 0;
652 unsigned char aBuffer[64 * 1024];
653 while(true)
654 {
655 unsigned Bytes = io_read(File, aBuffer, sizeof(aBuffer));
656 if(Bytes == 0)
657 break;
658 if(pSha256 != nullptr)
659 sha256_update(&Sha256Ctxt, aBuffer, Bytes);
660 if(pCrc != nullptr)
661 *pCrc = crc32(*pCrc, aBuffer, Bytes);
662 }
663 if(pSha256 != nullptr)
664 *pSha256 = sha256_finish(&Sha256Ctxt);
665
666 io_close(File);
667 return true;
668 }
669
670 struct CFindCBData
671 {

Callers 1

LoadFileMethod · 0.80

Calls 6

io_readFunction · 0.85
crc32Function · 0.85
io_closeFunction · 0.85
sha256_initFunction · 0.50
sha256_updateFunction · 0.50
sha256_finishFunction · 0.50

Tested by

no test coverage detected