From: shasckaw Date: 2004-01-28T08:14:54+09:00 Subject: Re: checksum with ruby, how? Mike Stok wrote: > In article <40168bd4$0$322$ba620e4c@news.skynet.be>, > shasckaw wrote: > >>Hello there, I need help. >>I'm searching for checksum funtionality to use with ruby, >>it seems that I have all I need with digest/md5 but I can't find any >>documentation about how to use it (searched on ruby-doc and RAA) >> >>Can someone help me? > > To set a baseline, I used md5sum to checksum "hello there\n" > > [mike@won mike]$ echo "hello there" > test.txt > [mike@won mike]$ md5sum test.txt > 2d01d5d9c24034d54fe4fba0ede5182d test.txt > > I used irb and some guesswork to figure out its methods, the guess being > that Digest::MD5 was the right package: Your guesswork has really been instructive in itself. Thanks a lot. > [snip] > It seems that you can initialise it with any String, so >>>File.open('/etc/passwd') do |f| >?> puts Digest::MD5.new(f.read).hexdigest >>>end > f087dea38c54a8b40d3dbc8b0becfb4c > => nil This is exactly what I needed. >or >>>d3 = Digest::MD5.new > => d41d8cd98f00b204e9800998ecf8427e >>>File.new('/etc/passwd').each_line { |l| d3 << l } > => # >>>d3.hexdigest > => "f087dea38c54a8b40d3dbc8b0becfb4c" > > are reasonable ways to checksum a file (at least on linux where I don't > care about binary mkode...) I'm using ruby on winNT. I've tested the code above and it gives exactly the same result, work fine then! :) > Hope this helps, This helped me a lot, thanks. And thanks to all other too. > Mike Lio