Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gem::Specification.new do |s|
s.name = 'open-s3uri'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Erik Terpstra'
s.email = 'erterpstra@gmail.com'
s.summary = 'Opens an S3 uri'
s.description = 'Opens an S3 uri like open-uri does for http URLs'
s.files = ['open-s3uri.rb']
s.require_path = '.'
s.add_dependency 'aws-sdk'
end
require 'aws-sdk'
class AWS::S3
# @param [String] S3 uri
# @return [AWS::S3::S3Object] S3 object (quacks like IO)
# @example Open an S3 object
# s3 = AWS::S3.new
# s3.open('s://mybucket/folder/hello.txt').read
def open(uri)
uri = URI(uri)
buckets[uri.host].objects[uri.path[1..-1]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment