mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Document both the support for generating tree hash by adding unaligned parts and the test.
This commit is contained in:
parent
80d3b69d91
commit
b71d80f59c
2 changed files with 16 additions and 4 deletions
|
@ -40,10 +40,15 @@ module Fog
|
|||
end
|
||||
|
||||
def initialize
|
||||
@last_chunk_digest = nil
|
||||
@last_chunk_digest_temp = nil
|
||||
@last_chunk_length = 0
|
||||
@last_chunk_digest = nil # Digest OBJECT for last chunk (Digest::SHA256)
|
||||
@last_chunk_digest_temp = nil # Digest VALUE for last chunk
|
||||
@last_chunk_length = 0 # Length of last chunk, always smaller than 1MB.
|
||||
@digest_stack = []
|
||||
# First position on stack corresponds to 1MB, second 2MB, third 4MB, fourt 8MB and so on.
|
||||
# In any time, the size of all already added parts is equal to sum of all existing (non-nil)
|
||||
# positions multiplied by that number, plus last_chunk_length for the remainder smaller than
|
||||
# one megabyte. So, if last_chunk_length is half megabyte, stack[0] is filled, stack[1] and
|
||||
# stack[2] empty and stack[3] filled, the size is 0.5MB + 1x1MB + 0x2MB + 0x4MB + 1x8MB = 9.5MB.
|
||||
end
|
||||
|
||||
def update_digest_stack(digest, stack)
|
||||
|
@ -52,7 +57,7 @@ module Fog
|
|||
digest = Digest::SHA256.digest(s + digest)
|
||||
stack[i] = nil
|
||||
else
|
||||
stack[i] = digest
|
||||
stack[i] = digest # Update this position with value obtained in previous run of cycle.
|
||||
digest = nil
|
||||
break
|
||||
end
|
||||
|
|
|
@ -59,14 +59,21 @@ Shindo.tests('AWS::Glacier | glacier tree hash calcuation', ['aws']) do
|
|||
|
||||
end
|
||||
|
||||
# Aligned is used in general sense of https://en.wikipedia.org/wiki/Data_structure_alignment
|
||||
# except we are not dealing with data in memory, but with parts in "virtual" space of whole file.
|
||||
# Tests for https://github.com/fog/fog-aws/issues/520 and https://github.com/fog/fog-aws/issues/521
|
||||
tests('multipart with unaligned parts') do
|
||||
tree_hash = Fog::AWS::Glacier::TreeHash.new
|
||||
part = ('x' * 512*1024)
|
||||
returns(Fog::AWS::Glacier::TreeHash.digest(part)) { tree_hash.add_part part }
|
||||
|
||||
# At this point, we have 0.5MB in tree_hash. That means that the next part we add will not be aligned,
|
||||
# because it will start on 0.5MB which is not 1MB boundary.
|
||||
part2 = ('x' * 512*1024) + ('y'*1024*1024) + ('z'* 512*1024)
|
||||
returns(Fog::AWS::Glacier::TreeHash.digest(part + part2)) { tree_hash.add_part part2 ; tree_hash.hexdigest }
|
||||
|
||||
# Here we are adding another 1.5MB to tree_hash which has size of 3.5MB. Again, 3.5MB is not on 1MB boundary,
|
||||
# so this is another unaligned part. It does test different part of code, though.
|
||||
tree_hash.add_part('z'* 512*1024 + 't'*1024*1024)
|
||||
|
||||
expected = OpenSSL::Digest::SHA256.hexdigest(
|
||||
|
|
Loading…
Reference in a new issue