Class: Chef::StreamingCookbookUploader::MultipartStream
- Defined in:
- lib/chef/streaming_cookbook_uploader.rb
Instance Method Summary collapse
-
#initialize(parts) ⇒ MultipartStream
constructor
A new instance of MultipartStream.
- #read(how_much) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(parts) ⇒ MultipartStream
Returns a new instance of MultipartStream.
156 157 158 159 160 |
# File 'lib/chef/streaming_cookbook_uploader.rb', line 156 def initialize(parts) @parts = parts @part_no = 0 @part_offset = 0 end |
Instance Method Details
#read(how_much) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/chef/streaming_cookbook_uploader.rb', line 166 def read(how_much) return nil if @part_no >= @parts.size how_much_current_part = @parts[@part_no].size - @part_offset how_much_current_part = if how_much_current_part > how_much how_much else how_much_current_part end how_much_next_part = how_much - how_much_current_part current_part = @parts[@part_no].read(@part_offset, how_much_current_part) # recurse into the next part if the current one was not large enough if how_much_next_part > 0 @part_no += 1 @part_offset = 0 next_part = read(how_much_next_part) current_part + if next_part next_part else '' end else @part_offset += how_much_current_part current_part end end |
#size ⇒ Object
162 163 164 |
# File 'lib/chef/streaming_cookbook_uploader.rb', line 162 def size @parts.inject(0) {|size, part| size + part.size} end |