Module: Nanoc3::PathnameExtensions

Included in:
Pathname
Defined in:
lib/nanoc3/base/core_ext/pathname.rb

Instance Method Summary collapse

Instance Method Details

#checksumString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Calculates the checksum for the file referenced to by this pathname. Any change to the file contents will result in a different checksum.

Returns:

  • (String)

    The checksum for this file



11
12
13
14
15
16
17
18
19
20
# File 'lib/nanoc3/base/core_ext/pathname.rb', line 11

def checksum
  digest = Digest::SHA1.new
  File.open(self.to_s, 'r') do |io|
    until io.eof
      data = io.read(2**10)
      digest.update(data)
    end
  end
  digest.hexdigest
end