Class: QcloudCos::Multipart

Inherits:
Object
  • Object
show all
Defined in:
lib/qcloud_cos/multipart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dst_path, src_path, options = {}) ⇒ Multipart

Returns a new instance of Multipart.



5
6
7
8
9
10
11
# File 'lib/qcloud_cos/multipart.rb', line 5

def initialize(dst_path, src_path, options = {})
  @dst_path = dst_path
  @src_path = src_path
  @options = options
  @bucket = options.delete(:bucket)
  @authorization = options.delete(:authorization)
end

Instance Attribute Details

#authorizationObject (readonly)

Returns the value of attribute authorization.



3
4
5
# File 'lib/qcloud_cos/multipart.rb', line 3

def authorization
  @authorization
end

#bucketObject (readonly)

Returns the value of attribute bucket.



3
4
5
# File 'lib/qcloud_cos/multipart.rb', line 3

def bucket
  @bucket
end

#dst_pathObject (readonly)

Returns the value of attribute dst_path.



3
4
5
# File 'lib/qcloud_cos/multipart.rb', line 3

def dst_path
  @dst_path
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/qcloud_cos/multipart.rb', line 3

def options
  @options
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/qcloud_cos/multipart.rb', line 3

def result
  @result
end

#src_pathObject (readonly)

Returns the value of attribute src_path.



3
4
5
# File 'lib/qcloud_cos/multipart.rb', line 3

def src_path
  @src_path
end

Instance Method Details

#upload(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/qcloud_cos/multipart.rb', line 13

def upload(&block)
  init_multipart
  return if complete?
  fail QcloudCos::MissingSessionIdError unless session

  offset = @result['offset'] || 0

  while offset < filesize
    filecontent = IO.read(src_path, slice_size, offset)
    break if upload_part(offset, filecontent, &block)
    offset += slice_size
  end
end