[Gambas-user] Checksum for array and collection

Benoit Minisini benoit.minisini at gambas-basic.org
Thu Mar 16 10:55:32 CET 2023


Le 16/03/2023 à 08:38, Christof Thalhofer a écrit :
> Hi everybody,
> 
> I'm in search for a function that returns a checksum for an array or a 
> collection so that I have the possibility to check if the size or 
> content has changed.
> 
> Any ideas?
> 
> To create a checksum for a string is easy, for that I use
> 
> 'Digest["sha1"](sCheckstring)'
> 
> with 'Digest' from gb.openssl.
> 
> But how create 'sCheckstring' which represents the content of the array?
> 
> A simple approach would be to use JSON.Encode($TheArray), but I wonder 
> if there are faster solutions?
> 
> Alles Gute
> 
> Christof Thalhofer
> 

You can serialize your data in a string, and then get the checksum. Note 
that you have now a 'gb.hash' component that implements the main 
checksum routines.

hString = Open String For Write
Write #hString, MyCollection As Collection ' Or whatever your data is
sString = Close #hString
Print Hash.SHA256(sString) ' From 'gb.hash'

Regards,

-- 
Benoît Minisini.



More information about the User mailing list