Class: Fog::Storage::AzureRM::Real::BlockFileStream

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb

Overview

This class is a stream to read chunk data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ BlockFileStream

Returns a new instance of BlockFileStream.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



21
22
23
# File 'lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb', line 21

def blocks
  @blocks
end

Instance Method Details

#read(size) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# 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