Class: Down::ChunkedIO
- Inherits:
-
Object
- Object
- Down::ChunkedIO
- Defined in:
- lib/down.rb
Instance Attribute Summary collapse
-
#tempfile ⇒ Object
readonly
Returns the value of attribute tempfile.
Instance Method Summary collapse
- #close ⇒ Object
- #each_chunk ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(options) ⇒ ChunkedIO
constructor
A new instance of ChunkedIO.
- #read(length = nil, outbuf = nil) ⇒ Object
- #rewind ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(options) ⇒ ChunkedIO
Returns a new instance of ChunkedIO.
140 141 142 143 144 145 |
# File 'lib/down.rb', line 140 def initialize() @size = .fetch(:size) @chunks = .fetch(:chunks) @on_close = .fetch(:on_close, ->{}) @tempfile = Tempfile.new("down", binmode: true) end |
Instance Attribute Details
#tempfile ⇒ Object (readonly)
Returns the value of attribute tempfile.
138 139 140 |
# File 'lib/down.rb', line 138 def tempfile @tempfile end |
Instance Method Details
#close ⇒ Object
169 170 171 172 |
# File 'lib/down.rb', line 169 def close terminate_download @tempfile.close! end |
#each_chunk ⇒ Object
156 157 158 159 |
# File 'lib/down.rb', line 156 def each_chunk return enum_for(__method__) if !block_given? yield download_chunk until download_finished? end |
#eof? ⇒ Boolean
161 162 163 |
# File 'lib/down.rb', line 161 def eof? @tempfile.eof? && download_finished? end |
#read(length = nil, outbuf = nil) ⇒ Object
151 152 153 154 |
# File 'lib/down.rb', line 151 def read(length = nil, outbuf = nil) download_chunk until enough_downloaded?(length) || download_finished? @tempfile.read(length, outbuf) end |
#rewind ⇒ Object
165 166 167 |
# File 'lib/down.rb', line 165 def rewind @tempfile.rewind end |
#size ⇒ Object
147 148 149 |
# File 'lib/down.rb', line 147 def size @size end |