Sha256: a994e6c6903960b230f845baf894af2fe5fe3aecef227a000e24e52e45e51a68

Contents?: true

Size: 1.11 KB

Versions: 41

Compression:

Stored size: 1.11 KB

Contents

require 'digest'

module Ridley::Chef
  # 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

41 entries across 41 versions & 1 rubygems

Version Path
ridley-4.0.0 lib/ridley/chef/digester.rb
ridley-3.1.0 lib/ridley/chef/digester.rb
ridley-3.0.0 lib/ridley/chef/digester.rb
ridley-3.0.0.rc1 lib/ridley/chef/digester.rb
ridley-2.5.1 lib/ridley/chef/digester.rb
ridley-2.5.0 lib/ridley/chef/digester.rb
ridley-2.4.4 lib/ridley/chef/digester.rb
ridley-2.4.3 lib/ridley/chef/digester.rb
ridley-2.4.2 lib/ridley/chef/digester.rb
ridley-2.4.1 lib/ridley/chef/digester.rb
ridley-2.4.0 lib/ridley/chef/digester.rb
ridley-2.3.0 lib/ridley/chef/digester.rb
ridley-2.2.0 lib/ridley/chef/digester.rb
ridley-2.1.0 lib/ridley/chef/digester.rb
ridley-2.0.0 lib/ridley/chef/digester.rb
ridley-1.7.1 lib/ridley/chef/digester.rb
ridley-1.7.0 lib/ridley/chef/digester.rb
ridley-1.6.0 lib/ridley/chef/digester.rb
ridley-1.5.3 lib/ridley/chef/digester.rb
ridley-1.2.6 lib/ridley/chef/digester.rb