Class: MP4::Source::S3
Constant Summary
Constants included from Base
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #eof? ⇒ Boolean
- #fetch(from, to) ⇒ Object
-
#initialize(bucket:, key:, client: nil) ⇒ S3
constructor
A new instance of S3.
- #open! ⇒ Object
- #pos ⇒ Object
- #read(n) ⇒ Object
- #reset_seek ⇒ Object
- #set_seek(n) ⇒ Object
- #size ⇒ Object
- #uri ⇒ Object
Methods included from Base
Constructor Details
#initialize(bucket:, key:, client: nil) ⇒ S3
Returns a new instance of S3.
51 52 53 54 55 56 57 |
# File 'lib/mp4/source/s3.rb', line 51 def initialize(bucket:, key:, client: nil) @bucket = bucket @key = key @client = client @position = 0 @file_size = nil end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
5 6 7 |
# File 'lib/mp4/source/s3.rb', line 5 def bucket @bucket end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/mp4/source/s3.rb', line 5 def key @key end |
Class Method Details
.from_uri(uri, client: nil) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/mp4/source/s3.rb', line 8 def from_uri(uri, client: nil) match = uri.match(%r{\As3://(?<bucket>[^/]+)/(?<key>.+)\z}) raise ArgumentError, "expected s3://BUCKET/KEY URI, got #{uri.inspect}" unless match new(bucket: match[:bucket], key: match[:key], client: client) end |
.reset_shared_client! ⇒ Object
22 23 24 |
# File 'lib/mp4/source/s3.rb', line 22 def reset_shared_client! @shared_client_mutex&.synchronize { @shared_client = nil } end |
.shared_client ⇒ Object
15 16 17 18 19 20 |
# File 'lib/mp4/source/s3.rb', line 15 def shared_client @shared_client_mutex ||= Mutex.new @shared_client_mutex.synchronize do @shared_client ||= build_client end end |
Instance Method Details
#close ⇒ Object
101 102 103 104 105 |
# File 'lib/mp4/source/s3.rb', line 101 def close # No per-instance connection to close; connections live in the shared # client's connection pool and are reused across sources. nil end |
#eof? ⇒ Boolean
89 90 91 |
# File 'lib/mp4/source/s3.rb', line 89 def eof? @position >= size end |
#fetch(from, to) ⇒ Object
77 78 79 |
# File 'lib/mp4/source/s3.rb', line 77 def fetch(from, to) get_range(from, to) end |
#open! ⇒ Object
63 64 65 66 |
# File 'lib/mp4/source/s3.rb', line 63 def open! size self end |
#pos ⇒ Object
93 94 95 |
# File 'lib/mp4/source/s3.rb', line 93 def pos @position end |
#read(n) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/mp4/source/s3.rb', line 68 def read(n) return ''.b if eof? to = [@position + n - 1, size - 1].min data = get_range(@position, to) @position += data.bytesize data end |
#reset_seek ⇒ Object
85 86 87 |
# File 'lib/mp4/source/s3.rb', line 85 def reset_seek @position = 0 end |
#set_seek(n) ⇒ Object
81 82 83 |
# File 'lib/mp4/source/s3.rb', line 81 def set_seek(n) @position = n.clamp(0, size) end |
#size ⇒ Object
97 98 99 |
# File 'lib/mp4/source/s3.rb', line 97 def size @file_size ||= client.head_object(bucket: @bucket, key: @key).content_length.to_i end |
#uri ⇒ Object
59 60 61 |
# File 'lib/mp4/source/s3.rb', line 59 def uri "s3://#{@bucket}/#{@key}" end |