From: Tim Hammerquist Date: 2006-01-01T07:32:56+09:00 Subject: Re: A few questions of function and style from a newbie Sven Johansson wrote: [ snip ] > Using: > require 'Digest/mp5' > Dir['*'].each {|f|print f, " "; puts > Digest::MD5.hexdigest(File.read(f)) if File.file? f} > > gives > > 001.mp3 6ce4ad47bfa79b6c0e48636040c1dfb9 > 002.mp3 6ce4ad47bfa79b6c0e48636040c1dfb9 > 0022-042.ogg 4cac5ea5e666942920aff937aa9b3ee5 > 0022-043.ogg 5947035093bbfa22a9e7cf6e69b82a4e > 0022-044.ogg 4cac5ea5e666942920aff937aa9b3ee5 > 0022-045.ogg 4cac5ea5e666942920aff937aa9b3ee5 > 0022-046.ogg 4cac5ea5e666942920aff937aa9b3ee5 > 0022-047.ogg 4cac5ea5e666942920aff937aa9b3ee5 > [snip] > > which clearly isn't good. However, both your suggestested > alternatives above work just fine. It would seem that binary > mode really is a must on Win32 - exhanging 'rb' for 'r' in > those suggestions gives me the hash repeat problem again. Good > to know. Just for our edification, would you run this following code on those same files? require 'digest/md5' files = Dir['*'].select { |f| File.file?(f) } files.each { |filename| fs_size = File.size(filename) # get size of file from OS data = File.read(filename) # read the file data_size = data.length # get the size of the data read hash = Digest::MD5.hexdigest(data) # calculate hash # compare amount of data on filesystem # with amount of data read puts "#{hash} - #{filename}: #{data_size}/#{fs_size}" } If my guess is correct, you should get some strange results. Please post these results, no matter the outcome, to the group so we can preserve a real-world example. Cheers! Tim Hammerquist