aliyun-sdk 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8813a13a2575ce30d0853dc4827ec61a10f8093e
4
- data.tar.gz: 986f85f79bc3f833dfa1708158cbdf789e3cd7ed
3
+ metadata.gz: 0a175798738ab2c2b9d5769d915913dbc7e025d4
4
+ data.tar.gz: af6c15c360539b23b596c93221660d44453d7349
5
5
  SHA512:
6
- metadata.gz: 8539e0c169ec08a28b4d1dd00cc6d93faba254d4a912d95987457b9dc216353cb922da0ffc04f969af767f44fed44bf27c008509f189c849b31c023af6b1dd87
7
- data.tar.gz: 06401e5cd1f01821e9e1c9de8f89871fb76dbcb7aaf7224b4abab7f624675ce59e6414f793e0fed3fc51dcdd724a1ee8515ed90b660425aff52967a54dc2831c
6
+ metadata.gz: f0ac5dd1199cef681699ef6ba6e7ed24fbc5c4a34e35a056c809a8eadb1cc0b76346b4e206d2cf8b1742d489de206349b6b5d4a5a53c0f0c4da6f05b66ec759f
7
+ data.tar.gz: 9b33d6da0bb5e48c70a353fa3babb202654d0ea4fd2e498ca16692bf7aad59124693057a5d90623f934f4a8fd7e78bca6aed81c33b91e1dbf27221fbd32c3206
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Change Log
2
2
 
3
+ ### v0.1.5
4
+
5
+ - Add open_timeout and read_timeout config
6
+ - Fix a concurrency bug in resumable_upload/download
7
+
3
8
  ### v0.1.4
4
9
 
5
10
  - Fix object key encoding problem
@@ -412,8 +412,8 @@ module Aliyun
412
412
  # 义的属性,它们会和object一起存储,在{#get_object}的时候会
413
413
  # 返回这些meta。属性的key不区分大小写。例如:{ 'year' => '2015' }
414
414
  # @option opts [Integer] :part_size 设置分片上传时每个分片的大小,
415
- # 默认为1 MB。断点上传最多允许10000个分片,如果文件大于10000个
416
- # 分片的大小,则每个分片的大小会大于1MB
415
+ # 默认为10 MB。断点上传最多允许10000个分片,如果文件大于10000个
416
+ # 分片的大小,则每个分片的大小会大于10MB
417
417
  # @option opts [String] :cpt_file 断点续传的checkpoint文件,如果
418
418
  # 指定的cpt文件不存在,则会在file所在目录创建一个默认的cpt文件,
419
419
  # 命名方式为:file.cpt,其中file是用户要上传的文件。在上传的过
@@ -459,8 +459,8 @@ module Aliyun
459
459
  # @param file [String] 本地文件的路径
460
460
  # @param opts [Hash] 下载文件的可选项
461
461
  # @option opts [Integer] :part_size 设置分片上传时每个分片的大小,
462
- # 默认为1 MB。断点下载最多允许100个分片,如果文件大于100个分片,
463
- # 则每个分片的大小会大于1MB
462
+ # 默认为10 MB。断点下载最多允许100个分片,如果文件大于100个分片,
463
+ # 则每个分片的大小会大于10 MB
464
464
  # @option opts [String] :cpt_file 断点续传的checkpoint文件,如果
465
465
  # 指定的cpt文件不存在,则会在file所在目录创建一个默认的cpt文件,
466
466
  # 命名方式为:file.cpt,其中file是用户要下载的文件名。在下载的过
@@ -30,6 +30,10 @@ module Aliyun
30
30
  # KEY SECRET,如果不填则会尝试匿名访问
31
31
  # @option opts [Boolean] :cname [可选] 指定endpoint是否是用户绑
32
32
  # 定的域名
33
+ # @option opts [Fixnum] :open_timeout [可选] 指定建立连接的超时
34
+ # 时间,默认为10秒
35
+ # @option opts [Fixnum] :read_timeout [可选] 指定等待响应的超时
36
+ # 时间,默认为120秒
33
37
  # @example 标准endpoint
34
38
  # oss-cn-hangzhou.aliyuncs.com
35
39
  # oss-cn-beijing.aliyuncs.com
@@ -9,7 +9,8 @@ module Aliyun
9
9
  #
10
10
  class Config < Struct::Base
11
11
 
12
- attrs :endpoint, :cname, :access_key_id, :access_key_secret
12
+ attrs :endpoint, :cname, :access_key_id, :access_key_secret,
13
+ :open_timeout, :read_timeout
13
14
 
14
15
  def initialize(opts = {})
15
16
  super(opts)
@@ -32,6 +32,8 @@ module Aliyun
32
32
  class HTTP
33
33
 
34
34
  DEFAULT_CONTENT_TYPE = 'application/octet-stream'
35
+ OPEN_TIMEOUT = 10
36
+ READ_TIMEOUT = 120
35
37
 
36
38
  ##
37
39
  # A stream implementation
@@ -64,7 +66,13 @@ module Aliyun
64
66
  outbuf << ret
65
67
  end
66
68
 
67
- ret.empty? ? nil : ret
69
+ # Conform to IO#read(length[, outbuf]):
70
+ # At end of file, it returns nil or "" depend on
71
+ # length. ios.read() and ios.read(nil) returns
72
+ # "". ios.read(positive-integer) returns nil.
73
+ return nil if ret.empty? && !bytes.nil? && bytes > 0
74
+
75
+ ret
68
76
  end
69
77
 
70
78
  def write(chunk)
@@ -231,7 +239,9 @@ module Aliyun
231
239
  :url => get_request_url(bucket, object),
232
240
  :headers => headers,
233
241
  :payload => http_options[:body],
234
- :block_response => block_response
242
+ :block_response => block_response,
243
+ :open_timeout => @config.open_timeout || OPEN_TIMEOUT,
244
+ :timeout => @config.read_timeout || READ_TIMEOUT
235
245
  ) do |response, request, result, &blk|
236
246
 
237
247
  if response.code >= 300
@@ -20,16 +20,31 @@ module Aliyun
20
20
 
21
21
  attrs :id, :object, :bucket, :creation_time, :options
22
22
 
23
+ def initialize(opts = {})
24
+ super(opts)
25
+
26
+ @mutex = Mutex.new
27
+ end
28
+
23
29
  private
24
30
  # Persist transaction states to file
25
31
  def write_checkpoint(states, file)
26
32
  md5= Util.get_content_md5(states.to_json)
27
- File.open(file, 'w') { |f| f.write(states.merge(md5: md5).to_json) }
33
+
34
+ @mutex.synchronize {
35
+ File.open(file, 'w') {
36
+ |f| f.write(states.merge(md5: md5).to_json)
37
+ }
38
+ }
28
39
  end
29
40
 
30
41
  # Load transaction states from file
31
42
  def load_checkpoint(file)
32
- states = JSON.load(File.read(file))
43
+ states = {}
44
+
45
+ @mutex.synchronize {
46
+ states = JSON.load(File.read(file))
47
+ }
33
48
  states.symbolize_keys!
34
49
  md5 = states.delete(:md5)
35
50
 
@@ -7,7 +7,7 @@ module Aliyun
7
7
  # A multipart upload transaction
8
8
  #
9
9
  class Upload < Transaction
10
- PART_SIZE = 4 * 1024 * 1024
10
+ PART_SIZE = 10 * 1024 * 1024
11
11
  READ_SIZE = 16 * 1024
12
12
  NUM_THREAD = 10
13
13
 
@@ -3,7 +3,7 @@
3
3
  module Aliyun
4
4
  module OSS
5
5
 
6
- VERSION = "0.1.4"
6
+ VERSION = "0.1.5"
7
7
 
8
8
  end # OSS
9
9
  end # Aliyun
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyun-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tianlong Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri