Class: Async::HTTP::Body::File
- Defined in:
- lib/async/http/body/file.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(path, range = nil, block_size: Async::IO::Stream::BLOCK_SIZE) ⇒ File
constructor
A new instance of File.
- #inspect ⇒ Object
- #join ⇒ Object
- #read ⇒ Object
Methods inherited from Readable
Constructor Details
#initialize(path, range = nil, block_size: Async::IO::Stream::BLOCK_SIZE) ⇒ File
Returns a new instance of File.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/async/http/body/file.rb', line 27 def initialize(path, range = nil, block_size: Async::IO::Stream::BLOCK_SIZE) @path = path @file = File.open(path) @block_size = block_size if range @offset = range.min @length = @remaining = range.size else @offset = 0 @length = @remaining = @file.size end end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
42 43 44 |
# File 'lib/async/http/body/file.rb', line 42 def length @length end |
Instance Method Details
#empty? ⇒ Boolean
44 45 46 |
# File 'lib/async/http/body/file.rb', line 44 def empty? @remaining == 0 end |
#inspect ⇒ Object
70 71 72 |
# File 'lib/async/http/body/file.rb', line 70 def inspect "\#<#{self.class} path=#{@path} offset=#{@offset} remaining=#{@remaining}>" end |
#join ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/async/http/body/file.rb', line 62 def join buffer = @file.read(@remaining) @remaining = 0 return buffer end |
#read ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/async/http/body/file.rb', line 48 def read if @remaining > 0 amount = [@remaining, @block_size].min if chunk = @file.read(amount) @remaining -= chunk.bytesize return chunk else @file.close end end end |