class Fog::Storage::AzureRM::Real::BlockFileStream

This class is a stream to read chunk data.

Attributes

blocks[R]

Public Class Methods

new(body) click to toggle source
# File lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb, line 23
def initialize(body)
  if body.respond_to?(:read)
    if body.respond_to?(:rewind)
      begin
        body.rewind
      rescue => ex
        Fog::Logger.debug "multipart_save_block_blob - body responds to :rewind but throws an exception when calling :rewind: #{ex.inspect}"
      end
    end
    @stream = body
  else
    @stream = StringIO.new(body)
  end
  @mutex = Mutex.new
  @blocks = []
end

Public Instance Methods

read(size) click to toggle source
# File lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb, line 40
def read(size)
  block_id = Base64.strict_encode64(random_string(32))
  data = nil
  id = 0
  @mutex.synchronize do
    data = @stream.read(size)
    return nil if data.nil?
    @blocks << [block_id]
    id = @blocks.size
  end
  BlockChunk.new(id, block_id, data)
end