Class: Bkblz::Task::DownloadFile
- Defined in:
- lib/bkblz/task/download_file.rb
Constant Summary
Constants included from ClassMethods
Instance Attribute Summary
Attributes inherited from BaseTask
Instance Method Summary collapse
Methods inherited from BaseTask
Methods included from ClassMethods
#check_one_of, #check_params, #check_required, #run, #task_param, #task_params
Methods included from TaskHelpers
Constructor Details
This class inherits a constructor from Bkblz::Task::BaseTask
Instance Method Details
#run_internal(session, params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bkblz/task/download_file.rb', line 10 def run_internal(session, params) partial_file_info = Bkblz::V1::Model::PartialFileInfo.new :file_id => params[:file_id] download_file_info = session.send( Bkblz::V1::DownloadFileByIdRequest.new partial_file_info).to_model unless download_file_info.sha1 == Digest::SHA1.hexdigest(download_file_info.body) raise "invalid checksum" end dir_path = params[:dir_path] unless ::File.directory? dir_path raise "dir_path is not a directory: %s" % dir_path end unless ::File.writable?(dir_path) raise "unable to write to directory %s" % dir_path end f_path = ::File.join dir_path, download_file_info.file_name if ::File.exists?(f_path) && !::File.writable?(f_path) raise "unable to write to existing file: %s" % f_path end ::File.binwrite(f_path, download_file_info.body) # This can be expensive, we're momentarily copying the body map = download_file_info.to_map map[:body] = "<omitted>" Bkblz::V1::Model::FileDownload.new map end |