partial fast MD5 sum for files

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

partial fast MD5 sum for files

Post 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)
SPAMINATOR NR.1
dige
Addict
Addict
Posts: 1412
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

Yes! Thats very fast .. thx Rings
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
dige
Addict
Addict
Posts: 1412
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

Fangles: you'll get it! :)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4791
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

dige wrote:Fangles: you'll get it! :)
Too late, My wife gave it to me and it's nasty!!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply