From: rtilley Date: 2006-03-20T04:33:49+09:00 Subject: Re: safe way to calc md5 on very large files Erik Veenstra wrote: >>Why we have no such method in the digest library? > > > I extended the MD5 class with a class method to build an MD5 > object directly from the contents of a given file. Should this be done to sha1, sha2, etc? > Use it like this: > > md5 = MD5.file("foo.bar") > > gegroet, > Erik V. - http://www.erikveen.dds.nl/ > > ---------------------------------------------------------------- > > require "md5" > > class MD5 > def self.file(file) > File.open(file, "rb") do |f| > res = self.new > while (data = f.read(4096)) > res << data > end > res > end > end > end > > ---------------------------------------------------------------- >