From: Robert Klemme Date: 2008-08-19T23:51:40+09:00 Subject: Re: reading x bytes at a time On 19 Aug., 02:21, Matt Harrison wrote: > I've just played around and found this seems to work: > > File.open(path, "r") do |fh| >   while (chunk = fh.read(blocksize)) >     outFH.puts Digest::MD5.hexdigest(chunk) + "\n" >   end > end > > Is this a good way to do it? Somehow my posting from today morning neither made it to Google news nor the mailing list. Strange... To sum it up: yes, that's a good way to do it. Few remarks: You do not need + "\n" because #puts will do this already. I prefer to open with "rb" instead of "r" in these cases. Makes scripts more portable plus helps documenting that this is really a binary stream. You can preallocate the buffer, this saves a bit of GC: File.open(path, "rb") do |fh| chunk = "" while fh.read(blocksize, chunk) outFH.puts Digest::MD5.hexdigest(chunk) end end Kind regards robert