Class: Fog::Storage::AzureRM::Real::BlobFileStream

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

Overview

This class is a stream to read chunk data.

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ BlobFileStream

Returns a new instance of BlobFileStream.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/azurerm/requests/storage/save_page_blob.rb', line 25

def initialize(body)
  if body.respond_to?(:read)
    if body.respond_to?(:rewind)
      begin
        body.rewind
      rescue => ex
        Fog::Logger.debug "save_page_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
  @count = 0
end

Instance Method Details

#read(size) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/azurerm/requests/storage/save_page_blob.rb', line 42

def read(size)
  data = nil
  id = 0
  start_range = 0
  @mutex.synchronize do
    start_range = @stream.pos
    data = @stream.read(size)
    return nil if data.nil?
    @count += 1
    id = @count
  end
  BlobChunk.new(id, start_range, data)
end