Method: Bundler::SharedHelpers#checksum_for_file

Defined in:
lib/bundler/shared_helpers.rb

#checksum_for_file(path, digest) ⇒ Object


206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/bundler/shared_helpers.rb', line 206

def checksum_for_file(path, digest)
  return unless path.file?
  # This must use File.read instead of Digest.file().hexdigest
  # because we need to preserve \n line endings on windows when calculating
  # the checksum
  SharedHelpers.filesystem_access(path, :read) do
    File.open(path, "rb") do |f|
      digest = SharedHelpers.digest(digest).new
      buf = String.new(capacity: 16_384, encoding: Encoding::BINARY)
      digest << buf while f.read(16_384, buf)
      digest.hexdigest
    end
  end
end