Class: IOStreams::S3::Reader
- Inherits:
-
Object
- Object
- IOStreams::S3::Reader
- Defined in:
- lib/io_streams/s3/reader.rb
Class Method Summary collapse
-
.open(uri, region: nil, **args, &block) ⇒ Object
Read from a AWS S3 file.
Class Method Details
.open(uri, region: nil, **args, &block) ⇒ Object
Read from a AWS S3 file
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/io_streams/s3/reader.rb', line 5 def self.open(uri, region: nil, **args, &block) raise(ArgumentError, 'file_name must be a URI string') unless uri.is_a?(String) IOStreams::S3.load_dependencies # https://aws.amazon.com/blogs/developer/using-resources/ s3 = region.nil? ? Aws::S3::Resource.new : Aws::S3::Resource.new(region: region) = IOStreams::S3.parse_uri(uri) object = s3.bucket([:bucket]).object([:key]) begin # Since S3 download only supports a push stream, write it to a tempfile first. IOStreams::File::Path.temp_file_name('iostreams_s3') do |file_name| args[:response_target] = file_name object.get(args) # Return a read stream IOStreams::File::Reader.open(file_name, &block) end end end |