Skip to content

Commit

Permalink
Merge pull request #399 from NickLaMuro/support-byte-count-for-s3-obj…
Browse files Browse the repository at this point in the history
…ect-store

[MiqS3Storage] Support @byte_count in #download_single
  • Loading branch information
carbonin authored Nov 5, 2018
2 parents a4b1ae0 + 89a3e3b commit 9e99167
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/gems/pending/util/object_storage/miq_s3_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ def download_single(source, destination)
logger.debug("Downloading [#{source}] from bucket [#{bucket_name}] to local file [#{destination}]")

with_standard_s3_error_handling("downloading", source) do
if destination.kind_of?(IO)
s3.client.get_object(:bucket => bucket_name, :key => object_key) do |chunk|
if destination.kind_of?(IO) || destination.kind_of?(StringIO)
get_object_opts = {
:bucket => bucket_name,
:key => object_key
}
# :range is indexed starting at zero
get_object_opts[:range] = "bytes=0-#{byte_count - 1}" if byte_count

s3.client.get_object(get_object_opts) do |chunk|
destination.write(chunk.force_encoding(destination.external_encoding))
end
else # assume file path
Expand Down

0 comments on commit 9e99167

Please sign in to comment.