Sha256: 4720a8ac84e6d48800e58b0870f6bbe2d79a4d5cba0d6d2266fe81ab52d44d8a

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 Bytes

Contents

module IOStreams
  module S3
    class Reader
      # Read from a AWS S3 file
      def self.open(uri, region: nil, **args, &block)
        raise(ArgumentError, 'file_name must be a URI string') unless uri.is_a?(String)

        s3      = region.nil? ? Aws::S3::Resource.new : Aws::S3::Resource.new(region: region)
        options = IOStreams::S3.parse_uri(uri)
        object  = s3.bucket(options[:bucket]).object(options[:key])

        begin
          # Since S3 download only supports a push stream, write it to a tempfile first.
          temp_file = Tempfile.new('rocket_job')

          args[:response_target] = temp_file.to_path
          object.get(args)

          block.call(temp_file)
        ensure
          temp_file.delete if temp_file
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iostreams-0.17.0 lib/io_streams/s3/reader.rb