lib/tori/backend/s3.rb in tori-0.6.1 vs lib/tori/backend/s3.rb in tori-0.6.2

- old
+ new

@@ -128,25 +128,21 @@ def url_for(filename, method) signer = Aws::S3::Presigner.new(client: client) signer.presigned_url(method, bucket: @bucket, key: filename) end - def open(filename) - blob = read(filename) - opt = [::File.basename(filename), ::File.extname(filename)] + def open(filename, opts = {}) + names = [::File.basename(filename), ::File.extname(filename)] + tmpdir = opts.delete(:tmpdir) if block_given? - Tempfile.create(opt) do |f| - f.write blob - f.fsync - f.rewind + Tempfile.create(names, tmpdir, opts) do |f| + get_object(key: filename, response_target: f.path) yield f end else - f = Tempfile.open(opt) - f.write blob - f.fsync - f.rewind + f = Tempfile.open(names, tmpdir, opts) + get_object(key: filename, response_target: f.path) f end end def get_object(opts={})