Class: Azure::BlobService

Inherits:
Object
  • Object
show all
Defined in:
lib/azure-contrib/blob_service.rb

Instance Method Summary collapse

Instance Method Details

#create_block_blob_with_chunking(container, blob, content_or_filepath, options = {}) ⇒ Object Also known as: create_block_blob

def get_blob_with_chunking(container, blob, option)

end

alias_method :get_blob_without_chunking, :get_blob alias_method :get_blob, :get_blob_with_chunking



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/azure-contrib/blob_service.rb', line 58

def create_block_blob_with_chunking(container, blob, content_or_filepath, options={})
  chunking = options.delete(:chunking)
  if chunking
    filepath = content_or_filepath
    block_list = upload_chunks(container, blob, filepath, options)

    unless block_list
      puts "EMPTY BLOCKLIST!"
      return false
    end

    puts "Done uploading #{block_list.size} blocks, committing ..."
    options[:blob_content_type] = options[:content_type]
    commit_blob_blocks(container, blob, block_list, options)
    puts "done."
  else
    content = content_or_filepath
    create_block_blob_without_chunking(container, blob, content, options)
  end
end

#upload_chunks(container, blob, filepath, options = {}) ⇒ Object

The maximum size for a block blob is 200 GB, and a block blob can include no more than 50,000 blocks. msdn.microsoft.com/en-us/library/azure/ee691964.aspx



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/azure-contrib/blob_service.rb', line 81

def upload_chunks(container, blob, filepath, options = {})
  counter = 1
  futures = []
  pool    = BlockActor.pool(size: 10, args: [self, container, blob, options])

  open(filepath, 'rb') do |f|
    f.each_chunk() {|chunk|
      block_id = counter.to_s.rjust(5, '0')
      futures << pool.future.upload(block_id, chunk)
      counter += 1
    }
  end

  block_list = futures.map(&:value)
  pool.terminate
  return block_list
end