Page 1 of 1

partial fast MD5 sum for files

Posted: Mon Apr 02, 2007 3:05 pm
by Rings
Code updated for 5.20+

specially to get Fangles working.... ;)
using Filemapping, works only in windows

Code: Select all

;;Build md5 sum for a partial file
;(c) 2007 by Siegfried Rings
;Windows only

Procedure.s MD5_PartCheck(Filename.s,Maxsize)
length=FileSize(Filename)
If Length<1: ProcedureReturn "":EndIf
If Length>Maxsize:Length=Maxsize:EndIf;Check for max 50000 bytes, should be enough

;md5.s="" 
handle=CreateFile_(Filename, #GENERIC_READ   , #FILE_SHARE_READ	, 0, #OPEN_EXISTING , #FILE_ATTRIBUTE_NORMAL,0)
If handle
 MapHandle = CreateFileMapping_(handle, 0, #PAGE_READONLY, 0, length, 0)
  If MapHandle
   ViewHandle = MapViewOfFile_(MapHandle, #FILE_MAP_READ   , 0, 0, 0)
   If ViewHandle
    md5.s=MD5Fingerprint(ViewHandle, length)
    UnmapViewOfFile_(ViewHandle)
  EndIf
  CloseHandle_(MapHandle)  ;okay, now close the Maphandle
 EndIf
 CloseHandle_(handle);okay, now close the Filehandle

 ProcedureReturn md5.s
EndIf 

EndProcedure

Debug MD5_PartCheck("c:\test.mp3",50000)

Posted: Tue Apr 03, 2007 2:24 pm
by dige
Yes! Thats very fast .. thx Rings

Posted: Wed Apr 04, 2007 1:08 am
by Fangbeast
dige wrote:Yes! Thats very fast .. thx Rings
He's still a cheeky bastard though (in a good way).

But dige, he keeps me slaving at this keyboard and now he wants drag and drop and sorting (AAAARRGHGHGHGHGHG).

Won't happen, I don't know drag and drop from the end of my ass.


EVIL GRIN(c) Copyright me!

Posted: Wed Apr 04, 2007 8:22 am
by dige
Fangles: you'll get it! :)

Posted: Wed Apr 04, 2007 12:35 pm
by Fangbeast
dige wrote:Fangles: you'll get it! :)
Too late, My wife gave it to me and it's nasty!!