[Gambas-user] Binary compare of files?

nando nando_f at ...951...
Sun Oct 19 06:02:02 CEST 2008


You want to use the code below, but use a large block size
like 8192 or 32768.  It doesn't have to be a perfect binary size.
I suggest not to use SHA or MD5 because if you're reading in 
the files to compute SHA or MD5, you might as well forget
wasting the time to compute and simply compare the strings.
It will be faster.  Plus MD5 is a one-way digest and it is
possible to get one identical answer digesting two different
strings - although highly unlikely.  SHA and MD5 are candidates
for scenario where the two files cannot be compared directly, so
the copy is digested and compared with a copy of the SHA or MD5.



---------- Original Message -----------
From: Stefano Palmeri <rospolosco at ...152...>
To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
Sent: Fri, 17 Oct 2008 10:03:45 +0200
Subject: Re: [Gambas-user] Binary compare of files?

> Il venerdì 17 ottobre 2008 08:18:20 Doriano Blengino ha scritto:
> > Kari Laine ha scritto:
> > > Hi All,
> > >
> > > could someone please give me a hint how compare two files for binary
> > > equality?
> > > I am doing it now int by int basis and it is taking years. I would like
> > > to read big chunks of both files and compare.
> > > Also I am thinking a possibility to read whole files in memory at once
> > > and then compare.
> >
> > I think you can read chunks of 256, 512, 1024 or more:
> >
> >   do
> >     read #file1, s1, -256
> >     read #file2, s2, -256
> >     if s1<>s2 then
> >       files_are_different()
> >       break
> >     endif
> >   while len(s1)=256
> >
> > Note the "-256" which reads up to 256 bytes, or up to the end of file.
> > Ideally, the higher the number the quicker should be, but some
> > experiment should be done. May be 8192, 16384 or so could do well.
> >
> > I didn't try this, however.
> >
> > Regards,
> > Doriano
> >
> 
> If you only want to know if two files are identical, 
> you could use md5sum.
> 
> Ciao,
> 
> Stefano
> 
> >
> >
> > -------------------------------------------------------------------------
> > This SF.Net email is sponsored by the Moblin Your Move Developer's
> > challenge Build the coolest Linux based applications with Moblin SDK & win
> > great prizes Grand prize is a trip for two to an Open Source event anywhere
> > in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list