Class: PKGWizard::StreamingUploader::MultipartStream
- Inherits:
-
Object
- Object
- PKGWizard::StreamingUploader::MultipartStream
- Defined in:
- lib/pkg-wizard/streaming_uploader.rb
Instance Method Summary collapse
-
#initialize(parts, blk = nil) ⇒ MultipartStream
constructor
A new instance of MultipartStream.
- #read(how_much) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(parts, blk = nil) ⇒ MultipartStream
Returns a new instance of MultipartStream.
96 97 98 99 100 101 102 103 104 |
# File 'lib/pkg-wizard/streaming_uploader.rb', line 96 def initialize(parts, blk = nil) @callback = nil if blk @callback = blk end @parts = parts @part_no = 0 @part_offset = 0 end |
Instance Method Details
#read(how_much) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/pkg-wizard/streaming_uploader.rb', line 110 def read(how_much) @callback.call(how_much) if @callback 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
106 107 108 |
# File 'lib/pkg-wizard/streaming_uploader.rb', line 106 def size @parts.inject(0) {|size, part| size + part.size} end |