Parent

Class/Module Index [+]

Quicksearch

Fog::AWS::Glacier::TreeHash

Public Class Methods

digest(body) click to toggle source
# File lib/fog/aws/glacier.rb, line 41
def self.digest(body)
  new.add_part(body)
end
new() click to toggle source
# File lib/fog/aws/glacier.rb, line 58
def initialize
  @digests = []
end

Public Instance Methods

add_part(bytes) click to toggle source
# File lib/fog/aws/glacier.rb, line 62
def add_part(bytes)
  part = self.digest_for_part(bytes)
  @digests << part
  part.unpack('H*').first
end
digest() click to toggle source
# File lib/fog/aws/glacier.rb, line 89
def digest
  reduce_digests(@digests)
end
digest_for_part(body) click to toggle source
# File lib/fog/aws/glacier.rb, line 68
def digest_for_part(body)
  chunk_count = [body.bytesize / MEGABYTE + (body.bytesize % MEGABYTE > 0 ? 1 : 0), 1].max
  if body.respond_to? :byteslice
    digests_for_part = chunk_count.times.collect {|chunk_index| Digest::SHA256.digest(body.byteslice(chunk_index * MEGABYTE, MEGABYTE))}
  else
    if body.respond_to? :encoding
      old_encoding = body.encoding
      body.force_encoding('BINARY')
    end
    digests_for_part = chunk_count.times.collect {|chunk_index| Digest::SHA256.digest(body.slice(chunk_index * MEGABYTE, MEGABYTE))}
    if body.respond_to? :encoding
      body.force_encoding(old_encoding)
    end
  end
  reduce_digests(digests_for_part)
end
hexdigest() click to toggle source
# File lib/fog/aws/glacier.rb, line 85
def hexdigest
  digest.unpack('H*').first
end
reduce_digests(digests) click to toggle source
# File lib/fog/aws/glacier.rb, line 45
def reduce_digests(digests)
  while digests.length > 1
    digests = digests.each_slice(2).collect do |pair|
      if pair.length == 2
        Digest::SHA256.digest(pair[0]+pair[1])
      else
        pair.first
      end
    end
  end
  digests.first
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.