Class: Hem::Lib::S3::Remote::File
- Inherits:
-
Object
- Object
- Hem::Lib::S3::Remote::File
- Defined in:
- lib/hem/lib/s3/remote/file.rb
Instance Method Summary collapse
- #buffer ⇒ Object
- #close ⇒ Object
-
#copy_from(io, opts = {}, &block) ⇒ Object
This is a bit nasty but it gets the job done.
-
#initialize(object, prefix) ⇒ File
constructor
A new instance of File.
- #read_io ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(object, prefix) ⇒ File
Returns a new instance of File.
6 7 8 9 10 11 |
# File 'lib/hem/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 20 |
# File 'lib/hem/lib/s3/remote/file.rb', line 13 def buffer @buffer_thread = Thread.new do @object.get do |chunk| @w_buffer.write chunk end @w_buffer.close # required for EOF end end |
#close ⇒ Object
26 27 28 29 30 |
# File 'lib/hem/lib/s3/remote/file.rb', line 26 def close @r_buffer.close unless @r_buffer.closed? @w_buffer.close unless @w_buffer.closed? @buffer_thread.exit if @buffer_thread end |
#copy_from(io, opts = {}, &block) ⇒ Object
This is a bit nasty but it gets the job done
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hem/lib/s3/remote/file.rb', line 37 def copy_from io, opts = {}, &block ninety_gb = 1024 * (90000000) # arbitrarily high number opts[:multipart_threshold] = ninety_gb if block_given? io.instance_eval " def read bytes data = super bytes @block.call(data) data end" io.instance_variable_set '@block', block end @object.upload_file(io, opts) end |
#read_io ⇒ Object
32 33 34 |
# File 'lib/hem/lib/s3/remote/file.rb', line 32 def read_io @r_buffer end |
#size ⇒ Object
22 23 24 |
# File 'lib/hem/lib/s3/remote/file.rb', line 22 def size @object.content_length end |