class Fog::AWS::Glacier::TreeHash
Public Class Methods
digest(body)
click to toggle source
# File lib/fog/aws/glacier.rb, line 40 def self.digest(body) new.add_part(body) end
new()
click to toggle source
# File lib/fog/aws/glacier.rb, line 57 def initialize @digests = [] end
Public Instance Methods
add_part(bytes)
click to toggle source
# File lib/fog/aws/glacier.rb, line 61 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 88 def digest reduce_digests(@digests) end
digest_for_part(body)
click to toggle source
# File lib/fog/aws/glacier.rb, line 67 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.map {|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.map {|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 84 def hexdigest digest.unpack('H*').first end
reduce_digests(digests)
click to toggle source
# File lib/fog/aws/glacier.rb, line 44 def reduce_digests(digests) while digests.length > 1 digests = digests.each_slice(2).map do |pair| if pair.length == 2 Digest::SHA256.digest(pair[0]+pair[1]) else pair.first end end end digests.first end