Method: FakeS3::FileStore#combine_object_parts

Defined in:
lib/fakes3/file_store.rb

#combine_object_parts(bucket, upload_id, object_name, parts, request) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/fakes3/file_store.rb', line 229

def combine_object_parts(bucket, upload_id, object_name, parts, request)
  upload_path   = File.join(@root, bucket.name)
  base_path     = File.join(upload_path, "#{upload_id}_#{object_name}")

  complete_file = ""
  chunk         = ""
  part_paths    = []

  parts.sort_by { |part| part[:number] }.each do |part|
    part_path    = "#{base_path}_part#{part[:number]}"
    content_path = File.join(part_path, , 'content')

    File.open(content_path, 'rb') { |f| chunk = f.read }
    etag = Digest::MD5.hexdigest(chunk)

    raise new Error "invalid file chunk" unless part[:etag] == etag
    complete_file << chunk
    part_paths    << part_path
  end

  object = do_store_object(bucket, object_name, complete_file, request)

  # clean up parts
  part_paths.each do |path|
    FileUtils.remove_dir(path)
  end

  object
end