module PredicsisMlSdk::UploadHelper
Constants
- OFFSET
Public Instance Methods
exists?(part_path, part_number, file_path)
click to toggle source
# File lib/predicsis_ml_sdk/upload_helper.rb, line 23 def exists?(part_path, part_number, file_path) if @nb_of_parts == part_number + 1 File.exist?(part_path) && File.size(part_path) == File.size(file_path).to_f - ((@nb_of_parts - 1) * OFFSET) else File.exist?(part_path) && File.size(part_path) == OFFSET end end
nb_of_parts(file)
click to toggle source
# File lib/predicsis_ml_sdk/upload_helper.rb, line 5 def nb_of_parts(file) @nb_of_parts ||= (File.size(file).to_f / OFFSET).ceil end
split_into_files(file_path, offset = OFFSET)
click to toggle source
# File lib/predicsis_ml_sdk/upload_helper.rb, line 9 def split_into_files(file_path, offset = OFFSET) dir = "tmp/multiparts/#{Time.now.to_i}" FileUtils.mkdir_p(dir) path = dir + '/part_' Thread.new(abort_on_exception: true) do nb_of_parts(file_path).times do |i| File.open(path + i.to_s.rjust(5, '0'), 'wb') do |tmp_file| tmp_file.write(IO.binread(file_path, offset, offset * i)) end end end path end