34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/fun_with/files/digest_methods.rb', line 34
def digest( digest_class = Digest::MD5, bytes = :all, offset = 0 )
if self.file? && self.readable?
if bytes == :all
digest_class.hexdigest( self.read )
elsif bytes.is_a?( Integer )
digest_class.hexdigest( self.read( bytes, offset ) )
else
raise ArgumentError.new( "FunWith::Files::DigestMethods.digest() error: bytes argument must be an integer or :all")
end
else
raise IOError.new( "Not a file: #{self.path}" ) unless self.file?
raise IOError.new( "Not readable: #{self.path}" ) unless self.readable?
end
end
|