class S3Ranger::CLI::Get

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/s3ranger/cli.rb, line 298
def initialize
  super 'get', false, false
  @short_desc = "Retrieve an object and save to the specified file"
  @has_prefix = 'required'
end

Public Instance Methods

run(s3, bucket, key, file, args) click to toggle source
# File lib/s3ranger/cli.rb, line 304
def run s3, bucket, key, file, args
  raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket
  raise WrongUsage.new(nil, "You need to inform a key") if not key
  raise WrongUsage.new(nil, "You need to inform a file") if not file

  # Saving the content to be downloaded to the current directory if the
  # destination is a directory
  path = File.absolute_path file
  path = S3Ranger.safe_join [path, File.basename(key)] if File.directory? path
  File.open(path, 'wb') do |f|
    s3.buckets[bucket].objects[key].read do |chunk| f.write(chunk) end
  end
end