From: Michael Neumann Date: 2004-10-15T00:53:37+09:00 Subject: [RCR] digest/from_io Hi, Would be nice to have in standard Ruby, as it's common to calculate a digest of a file. Example of usage: require 'digest/sha1' require 'digest/from_io' File.open('/tmp/x') {|f| Digest::SHA1.from_io(f) } Implementation: # file: digest/from_io.rb class Digest::Base def self.from_io(io, block_size=8*1024) digest = new while data = io.read(block_size) digest.update(data) end digest end end Another addition would be the raw_digest method (which of course could be better implemented in C): require 'enumerator' class Digest::Base def raw_digest hexdigest.to_enum(:scan, /../).map {|byte| byte.to_i(16).chr}.join end alias rawdigest raw_digest end Gavin, feel free to add it to extlib/addlib if you think it's worth. matz, do you think, we can add from_io to stdlib? Regards, Michael