以下是Java中我无法在Delphi中实现的问题的解决方案. How to read first and last 64kb of a video file in Java?
到目前为止我的Delphi代码:
function TSubdbAPI.GetHashFromfile(const Afilename: string): string;var Md5: TIDHashMessageDigest5; filestream: TfileStream; Buffer: TByteArray;begin Md5 := TIDHashMessageDigest5.Create; filestream := TfileStream.Create(Afilename,fmOpenRead,fmShareDenyWrite); try if filestream.Size > 0 then begin filestream.Read(Buffer,1024 * 64); filestream.Seek(64,soFromEnd); filestream.Read(Buffer,1024 * 64); Result := Md5.HashStreamAsHex(filestream); end; finally Md5.Free; filestream.Free; end;end;
我没有得到官方API.API url here所述的准确的md5哈希值.我正在使用Delphi XE8.
解决方法 该API使用的hash function
描述为: Our hash is composed by taking the first and the last 64kb of the
vIDeo file,putting all together and generating a md5 of the resulting
data (128kb).
我可以在你的代码中看到一些问题.您正在散列文件流,而不是您的缓冲区数组.除非您通过后续读取文件流覆盖该数组.并且您试图仅搜索64个字节,并且超出流的末尾(您需要使用负值来从流的末尾搜索).尝试这样的事情:
type ESubDBException = class(Exception);function TSubdbAPI.GetHashFromfile(const Afilename: string): string;const KiloByte = 1024; DataSize = 64 * KiloByte;var Digest: TIDHashMessageDigest5; fileStream: TfileStream; HashStream: TMemoryStream;begin fileStream := TfileStream.Create(Afilename,fmShareDenyWrite); try if fileStream.Size < DataSize then raise ESubDBException.Create('file is smaller than the minimum required for ' + 'calculating API hash.'); HashStream := TMemoryStream.Create; try HashStream.copyFrom(fileStream,DataSize); fileStream.Seek(-DataSize,soEnd); HashStream.copyFrom(fileStream,DataSize); Digest := TIDHashMessageDigest5.Create; try HashStream.position := 0; Result := Digest.HashStreamAsHex(HashStream); finally Digest.Free; end; finally HashStream.Free; end; finally fileStream.Free; end;end;总结
以上是内存溢出为你收集整理的如何在Delphi中读取第一个和最后一个64kb的视频文件?全部内容,希望文章能够帮你解决如何在Delphi中读取第一个和最后一个64kb的视频文件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)