[英]Parsing Data chuck of a .wav file in c++
I am using a SHA1 Hash to verify the authenticity of a .wav
file.我正在使用 SHA1 哈希来验证.wav
文件的真实性。 The SHA1 function I am using takes in three parameter:我使用的 SHA1 函数接受三个参数:
.auth
extension指向带有.auth
扩展名的身份验证文件的指针.wav
file (which must be less than 42000 bytes in size)从.wav
文件读取的数据缓冲区(大小必须小于 42000 字节)for (int i = 0; i < size_buffer; i++) {
DataBuffer[i] = fgetc(WavResult);
}
util_sha1_calculate(&AuthContext, DataBuffer, size_buffer);
How can I set a read function to read 42000 bytes, transfer the data to util_sha1_calculate(&AuthContext, DataBuffer, size_buffer)
, and start from the position it left off when the loop is repeated, and proceed to read then next 42000 bytes?如何设置读取函数以读取 42000 字节,将数据传输到util_sha1_calculate(&AuthContext, DataBuffer, size_buffer)
,并从重复循环时停止的位置开始,然后继续读取下一个 42000 字节?
You can put your shown for
loop inside of another outer loop that runs until EOF is reached, eg:您可以将显示的for
循环放在另一个运行直到达到 EOF 的外部循环中,例如:
size_t size;
int ch;
while (!feof(WavResult))
{
size = 0;
for (int i = 0; i < size_buffer; i++) {
ch = fgetc(WavResult);
if (ch == EOF) break;
DataBuffer[size++] = (char) ch;
}
if (size > 0)
util_sha1_calculate(&AuthContext, DataBuffer, size);
}
However, you should consider replacing the inner for
loop with a single call to fread()
instead, eg:但是,您应该考虑使用对fread()
的单个调用替换内部for
循环,例如:
size_t nRead;
while ((nRead = fread(DataBuffer, 1, size_buffer, WavResult)) > 0)
{
util_sha1_calculate(&AuthContext, DataBuffer, nRead);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.