# class Chef::CookbookSiteStreamingUploader::MultipartStream

### Public Class Methods

new(parts) click to toggle source

    # File lib/chef/cookbook_site_streaming_uploader.rb, line 201
    def initialize(parts)
      @parts = parts
      @part_no = 0
      @part_offset = 0
    end

### Public Instance Methods

read(how_much, dst_buf = nil) click to toggle source

    # File lib/chef/cookbook_site_streaming_uploader.rb, line 211
    def read(how_much, dst_buf = nil)
      if @part_no >= @parts.size
        dst_buf.replace('') if dst_buf
        return dst_buf
      end

      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)
        result = current_part + if next_part
                         next_part
                       else
                         ''
                       end
      else
        @part_offset += how_much_current_part
        result = current_part
      end
      dst_buf ? dst_buf.replace(result || '') : result
    end

size() click to toggle source

    # File lib/chef/cookbook_site_streaming_uploader.rb, line 207
    def size
      @parts.inject(0) {|size, part| size + part.size}
    end