mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[AWS|Glacier] byteslice is only available in 1.9.3 - add fallback for 1.9.2
This commit is contained in:
parent
90d0126f3f
commit
3c0f47f377
2 changed files with 16 additions and 1 deletions
|
@ -67,7 +67,14 @@ module Fog
|
|||
|
||||
def digest_for_part(body)
|
||||
chunk_count = [body.bytesize / MEGABYTE + (body.bytesize % MEGABYTE > 0 ? 1 : 0), 1].max
|
||||
digests_for_part = chunk_count.times.collect {|chunk_index| Digest::SHA256.digest(body.byteslice(chunk_index * MEGABYTE, MEGABYTE))}
|
||||
if body.respond_to? :byteslice
|
||||
digests_for_part = chunk_count.times.collect {|chunk_index| Digest::SHA256.digest(body.byteslice(chunk_index * MEGABYTE, MEGABYTE))}
|
||||
else
|
||||
old_encoding = body.encoding
|
||||
body.force_encoding('BINARY')
|
||||
digests_for_part = chunk_count.times.collect {|chunk_index| Digest::SHA256.digest(body.byteslice(chunk_index * MEGABYTE, MEGABYTE))}
|
||||
body.force_encoding(old_encoding)
|
||||
end
|
||||
reduce_digests(digests_for_part)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,6 +4,14 @@ Shindo.tests('AWS::Glacier | glacier tree hash calcuation', ['aws']) do
|
|||
returns(Digest::SHA256.hexdigest('')) { Fog::AWS::Glacier::TreeHash.digest('')}
|
||||
end
|
||||
|
||||
tests('tree_hash(multibyte characters)') do
|
||||
body = ("\xC2\xA1".force_encoding('UTF-8') * 1024*1024)
|
||||
expected = Digest::SHA256.hexdigest(
|
||||
Digest::SHA256.digest("\xC2\xA1" * 1024*512) + Digest::SHA256.digest("\xC2\xA1" * 1024*512)
|
||||
)
|
||||
returns(expected) { Fog::AWS::Glacier::TreeHash.digest(body)}
|
||||
end
|
||||
|
||||
tests('tree_hash(power of 2 number of parts)') do
|
||||
body = ('x' * 1024*1024) + ('y'*1024*1024) + ('z'*1024*1024) + ('t'*1024*1024)
|
||||
expected = Digest::SHA256.hexdigest(
|
||||
|
|
Loading…
Add table
Reference in a new issue