Sha256: 438cf816a5c5c4904093d5cbcfb61e30ef0735b530d0cf316b05afb0d67a4ba8

Contents?: true

Size: 1.16 KB

Versions: 21

Compression:

Stored size: 1.16 KB

Contents

require 'digest'

module Ridley::Chef
  # @author Jamie Winsor <reset@riotgames.com>
  #
  # Borrowed and modified from: {https://github.com/opscode/chef/blob/11.4.0/lib/chef/digester.rb}
  class Digester
    class << self
      def instance
        @instance ||= new
      end

      def checksum_for_file(*args)
        instance.checksum_for_file(*args)
      end

      def md5_checksum_for_file(*args)
        instance.generate_md5_checksum_for_file(*args)
      end
    end

    def validate_checksum(*args)
      self.class.validate_checksum(*args)
    end

    def checksum_for_file(file)
      generate_checksum(file)
    end

    def generate_checksum(file)
      checksum_file(file, Digest::SHA256.new)
    end

    def generate_md5_checksum_for_file(file)
      checksum_file(file, Digest::MD5.new)
    end

    def generate_md5_checksum(io)
      checksum_io(io, Digest::MD5.new)
    end

    private

      def checksum_file(file, digest)
        File.open(file, 'rb') { |f| checksum_io(f, digest) }
      end

      def checksum_io(io, digest)
        while chunk = io.read(1024 * 8)
          digest.update(chunk)
        end
        digest.hexdigest
      end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ridley-1.0.0.rc2 lib/ridley/chef/digester.rb
ridley-1.0.0.rc1 lib/ridley/chef/digester.rb
ridley-0.12.4 lib/ridley/chef/digester.rb
ridley-0.12.3 lib/ridley/chef/digester.rb
ridley-0.12.2 lib/ridley/chef/digester.rb
ridley-0.12.1 lib/ridley/chef/digester.rb
ridley-0.12.0 lib/ridley/chef/digester.rb
ridley-0.11.2 lib/ridley/chef/digester.rb
ridley-0.12.0.rc1 lib/ridley/chef/digester.rb
ridley-0.11.1 lib/ridley/chef/digester.rb
ridley-0.10.2 lib/ridley/chef/digester.rb
ridley-0.9.1 lib/ridley/chef/digester.rb
ridley-0.10.1 lib/ridley/chef/digester.rb
ridley-0.11.0.rc1 lib/ridley/chef/digester.rb
ridley-0.10.0 lib/ridley/chef/digester.rb
ridley-0.10.0.rc3 lib/ridley/chef/digester.rb
ridley-0.10.0.rc2 lib/ridley/chef/digester.rb
ridley-0.10.0.rc1 lib/ridley/chef/digester.rb
ridley-0.9.0 lib/ridley/chef/digester.rb
ridley-0.8.6 lib/ridley/chef/digester.rb