Class: Hobo::Lib::S3::Remote::File
- Inherits:
-
Object
- Object
- Hobo::Lib::S3::Remote::File
- Defined in:
- lib/hobo/lib/s3/remote/file.rb
Instance Method Summary collapse
- #buffer ⇒ Object
- #close ⇒ Object
-
#initialize(object, prefix) ⇒ File
constructor
A new instance of File.
- #read(bytes) ⇒ Object
- #size ⇒ Object
- #write(opts = {}) ⇒ Object
Constructor Details
#initialize(object, prefix) ⇒ File
Returns a new instance of File.
6 7 8 9 10 11 |
# File 'lib/hobo/lib/s3/remote/file.rb', line 6 def initialize object, prefix @object = object @prefix = prefix @r_buffer, @w_buffer = IO.pipe @buffer_thread = nil end |
Instance Method Details
#buffer ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/hobo/lib/s3/remote/file.rb', line 13 def buffer @buffer_thread = Thread.new do @object.read do |chunk| @w_buffer.write chunk end end end |
#close ⇒ Object
36 37 38 39 40 |
# File 'lib/hobo/lib/s3/remote/file.rb', line 36 def close @r_buffer.close @w_buffer.close @buffer_thread.exit if @buffer_thread end |
#read(bytes) ⇒ Object
21 22 23 |
# File 'lib/hobo/lib/s3/remote/file.rb', line 21 def read bytes @r_buffer.readpartial(bytes) end |
#size ⇒ Object
32 33 34 |
# File 'lib/hobo/lib/s3/remote/file.rb', line 32 def size @object.content_length end |
#write(opts = {}) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/hobo/lib/s3/remote/file.rb', line 25 def write opts = {} s3_opts = { :single_request => true, :content_length => opts[:size] } @object.write s3_opts do |buffer, bytes| yield buffer, bytes end end |