在为文件的一部分获取正确的 md5 哈希时遇到问题,我的代码如下所示。每当我阅读整个文件(没有搜索和阅读)时,它都很好。错误在哪里?
long length = (offset_end - offset_start) + 1;
char* buffer = new char[length];
std::ifstream ifs(downloadFile->url_hdd.c_str(), std::ios::binary);
ifs.seekg(offset_start, std::ios::beg);
ifs.read(buffer, length);
ifs.close();
std::stringstream stringStream(buffer);
Poco::MD5Engine md5;
Poco::DigestOutputStream outstr(md5);
outstr << stringStream.str();
outstr.flush(); //to pass everything to the digest engine
const Poco::DigestEngine::Digest& digest = md5.digest();
std::string md5string = Poco::DigestEngine::digestToHex(digest);