我用wininet的一些功能下载文件:
Url := source_file;
destinationfilename := destination_file;
hInet := InternetOpen(PChar(application.title), INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
hFile := InternetOpenURL(hInet, PChar(Url), nil, 0,
INTERNET_FLAG_NO_CACHE_WRITE, 0);
if Assigned(hFile) then
begin
AssignFile(localFile, destinationfilename);
Rewrite(localFile, 1);
repeat
InternetReadFile(hFile, @Buffer, SizeOf(Buffer), bytesRead);
BlockWrite(localFile, Buffer, bytesRead);
current_size := current_size + bytesRead;
until (bytesRead = 0) OR (terminated = True);
CloseFile(localFile);
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hInet);
我试图确定下载速度,但得到一些奇怪的值:
...
repeat
QueryPerformanceFrequency(iCounterPerSec);
QueryPerformanceCounter(T1);
InternetReadFile(hFile, @Buffer, SizeOf(Buffer), bytesRead);
BlockWrite(localFile, Buffer, bytesRead);
current_size := current_size + bytesRead;
QueryPerformanceCounter(T2);
_speed := round((bytesRead / 1024) / ((T2 - T1) / iCounterPerSec));
download_speed := inttostr(_speed) + ' kbps';
until (bytesRead = 0) OR (terminated = True);
...
所以问题是我如何确定以 kbps 为单位的下载速度?提前感谢您的回答!