cos 0.1.0 → 0.1.1
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 +4 -4
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -2
- data/Gemfile +4 -1
- data/LICENSE +191 -0
- data/README.md +2014 -17
- data/Rakefile +23 -6
- data/bin/cos +325 -0
- data/bin/setup +1 -3
- data/cos.gemspec +24 -13
- data/lib/cos.rb +41 -4
- data/lib/cos/api.rb +289 -0
- data/lib/cos/bucket.rb +731 -0
- data/lib/cos/checkpoint.rb +62 -0
- data/lib/cos/client.rb +58 -0
- data/lib/cos/config.rb +102 -0
- data/lib/cos/dir.rb +301 -0
- data/lib/cos/download.rb +252 -0
- data/lib/cos/exception.rb +62 -0
- data/lib/cos/file.rb +152 -0
- data/lib/cos/http.rb +95 -0
- data/lib/cos/logging.rb +47 -0
- data/lib/cos/resource.rb +201 -0
- data/lib/cos/signature.rb +119 -0
- data/lib/cos/slice.rb +292 -0
- data/lib/cos/struct.rb +49 -0
- data/lib/cos/tree.rb +165 -0
- data/lib/cos/util.rb +82 -0
- data/lib/cos/version.rb +2 -2
- data/spec/cos/bucket_spec.rb +562 -0
- data/spec/cos/client_spec.rb +77 -0
- data/spec/cos/dir_spec.rb +195 -0
- data/spec/cos/download_spec.rb +105 -0
- data/spec/cos/http_spec.rb +70 -0
- data/spec/cos/signature_spec.rb +83 -0
- data/spec/cos/slice_spec.rb +302 -0
- data/spec/cos/struct_spec.rb +38 -0
- data/spec/cos/tree_spec.rb +322 -0
- data/spec/cos/util_spec.rb +106 -0
- data/test/download_test.rb +44 -0
- data/test/list_test.rb +43 -0
- data/test/upload_test.rb +48 -0
- metadata +132 -21
- data/.idea/.name +0 -1
- data/.idea/cos.iml +0 -49
- data/.idea/encodings.xml +0 -6
- data/.idea/misc.xml +0 -14
- data/.idea/modules.xml +0 -8
- data/.idea/workspace.xml +0 -465
- data/bin/console +0 -14
@@ -0,0 +1,106 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module COS
|
6
|
+
|
7
|
+
describe Util do
|
8
|
+
|
9
|
+
# 测试文件sha1是否正确
|
10
|
+
it 'should get correct file sha1' do
|
11
|
+
file = './file_to_test.log'
|
12
|
+
File.open(file, 'w') do |f|
|
13
|
+
(1..10).each do |i|
|
14
|
+
f.puts i.to_s.rjust(9, '0')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
result = Util.file_sha1(file)
|
18
|
+
expect(result).to eq('0ee35e888cafa2e9644ddaa421ad44486abd7cf7')
|
19
|
+
end
|
20
|
+
|
21
|
+
# 测试字符串sha1是否正确
|
22
|
+
it 'should get correct string sha1' do
|
23
|
+
value = ''
|
24
|
+
result = Util.string_sha1(value)
|
25
|
+
expect(result).to eq('da39a3ee5e6b4b0d3255bfef95601890afd80709')
|
26
|
+
|
27
|
+
value = 'aaaaaa bbbbbb cccccc'
|
28
|
+
result = Util.string_sha1(value)
|
29
|
+
expect(result).to eq('24662fa2abcb5cfb57f3e889216647c2cac06d31')
|
30
|
+
end
|
31
|
+
|
32
|
+
# 测试解析list时的path
|
33
|
+
it 'should get correct list path' do
|
34
|
+
result = Util.get_list_path('/path1/', 'file', true)
|
35
|
+
expect(result).to eq('/path1/file')
|
36
|
+
|
37
|
+
result = Util.get_list_path('/path1', 'file', true)
|
38
|
+
expect(result).to eq('/path1/file')
|
39
|
+
|
40
|
+
result = Util.get_list_path('path1', 'file', true)
|
41
|
+
expect(result).to eq('/path1/file')
|
42
|
+
|
43
|
+
result = Util.get_list_path('/path1/', 'path2')
|
44
|
+
expect(result).to eq('/path1/path2/')
|
45
|
+
|
46
|
+
result = Util.get_list_path('path1', 'path2')
|
47
|
+
expect(result).to eq('/path1/path2/')
|
48
|
+
end
|
49
|
+
|
50
|
+
# 测试获取resource_path
|
51
|
+
it 'should get correct resource_path' do
|
52
|
+
result = Util.get_resource_path('10000', 'bucket', 'path1')
|
53
|
+
expect(result).to eq('/10000/bucket/path1/')
|
54
|
+
|
55
|
+
result = Util.get_resource_path('10000', 'bucket', '/path1/')
|
56
|
+
expect(result).to eq('/10000/bucket/path1/')
|
57
|
+
|
58
|
+
result = Util.get_resource_path('10000', 'bucket', 'path1', 'file1')
|
59
|
+
expect(result).to eq('/10000/bucket/path1/file1')
|
60
|
+
|
61
|
+
result = Util.get_resource_path('10000', 'bucket', '/path1/', 'file1')
|
62
|
+
expect(result).to eq('/10000/bucket/path1/file1')
|
63
|
+
|
64
|
+
expect do
|
65
|
+
Util.get_resource_path('10000', 'bucket', '/path1/', 'file1/')
|
66
|
+
end.to raise_error(ClientError, "File name can't start or end with '/'")
|
67
|
+
|
68
|
+
expect do
|
69
|
+
Util.get_resource_path('10000', 'bucket', '/path1/', '/file1')
|
70
|
+
end.to raise_error(ClientError, "File name can't start or end with '/'")
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
# 测试获取resource_path包含文件
|
75
|
+
it 'should get correct resource_path_or_file' do
|
76
|
+
result = Util.get_resource_path_or_file('10000', 'bucket', 'file')
|
77
|
+
expect(result).to eq('/10000/bucket/file')
|
78
|
+
|
79
|
+
result = Util.get_resource_path_or_file('10000', 'bucket', 'path1/')
|
80
|
+
expect(result).to eq('/10000/bucket/path1/')
|
81
|
+
|
82
|
+
result = Util.get_resource_path_or_file('10000', 'bucket', '/path1/')
|
83
|
+
expect(result).to eq('/10000/bucket/path1/')
|
84
|
+
|
85
|
+
result = Util.get_resource_path_or_file('10000', 'bucket', '/path1/file')
|
86
|
+
expect(result).to eq('/10000/bucket/path1/file')
|
87
|
+
|
88
|
+
result = Util.get_resource_path_or_file('10000', 'bucket', 'path1/file')
|
89
|
+
expect(result).to eq('/10000/bucket/path1/file')
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should get local path' do
|
94
|
+
expect(Util.get_local_path('/etc/')).to eq('/etc')
|
95
|
+
|
96
|
+
rand_path = rand(0..999)
|
97
|
+
expect(Util.get_local_path("/tmp/#{rand_path}/")).to eq("/tmp/#{rand_path}")
|
98
|
+
|
99
|
+
expect do
|
100
|
+
Util.get_local_path('/tmp/gewg414thgr42y2h33333', true)
|
101
|
+
end.to raise_error(LocalPathNotExist)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# 下载集成测试
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'memory_profiler'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
9
|
+
|
10
|
+
require 'cos'
|
11
|
+
|
12
|
+
class DownloadTest < Minitest::Test
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@bucket = COS.client(config: '~/.cos.yml').bucket
|
16
|
+
@file_store = '~/Desktop/download_test/1.5GB.bin'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_download_big_file
|
20
|
+
skip
|
21
|
+
|
22
|
+
memory_profiler do
|
23
|
+
|
24
|
+
Benchmark.bm(32) do |bm|
|
25
|
+
bm.report('Slice Download 1.5GB File') do
|
26
|
+
@bucket.download('test/1.5GB.bin', @file_store)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def memory_profiler
|
36
|
+
report = MemoryProfiler.report do
|
37
|
+
yield if block_given?
|
38
|
+
end
|
39
|
+
|
40
|
+
# 打印内存信息
|
41
|
+
report.pretty_print
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/test/list_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# 列表集成测试
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'memory_profiler'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
9
|
+
|
10
|
+
require 'cos'
|
11
|
+
|
12
|
+
class ListTest < Minitest::Test
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@bucket = COS.client(config: '~/.cos.yml').bucket
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_list_big_dir
|
19
|
+
memory_profiler do
|
20
|
+
|
21
|
+
Benchmark.bm(32) do |bm|
|
22
|
+
bm.report('List a big dir') do
|
23
|
+
@bucket.list('big_dir').each do |res|
|
24
|
+
puts res.name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def memory_profiler
|
35
|
+
report = MemoryProfiler.report do
|
36
|
+
yield if block_given?
|
37
|
+
end
|
38
|
+
|
39
|
+
# 打印内存信息
|
40
|
+
report.pretty_print
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/test/upload_test.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# 上传集成测试
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'memory_profiler'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
9
|
+
|
10
|
+
require 'cos'
|
11
|
+
|
12
|
+
class UploadTest < Minitest::Test
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@bucket = COS.client(config: '~/.cos.yml').bucket
|
16
|
+
@file_src = '~/Desktop/upload_test/1.5GB.bin'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_upload_big_file
|
20
|
+
skip
|
21
|
+
|
22
|
+
memory_profiler do
|
23
|
+
|
24
|
+
Benchmark.bm(32) do |bm|
|
25
|
+
bm.report('Slice Upload 1.5GB File') do
|
26
|
+
# 修改文件防止秒传命中
|
27
|
+
`echo 1 >> #{@file_src}`
|
28
|
+
# 删除文件
|
29
|
+
@bucket.delete!('test/1.5GB.bin')
|
30
|
+
@bucket.upload('test/', '1.5GB.bin', @file_src, auto_create_folder: true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def memory_profiler
|
40
|
+
report = MemoryProfiler.report do
|
41
|
+
yield if block_given?
|
42
|
+
end
|
43
|
+
|
44
|
+
# 打印内存信息
|
45
|
+
report.pretty_print
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
metadata
CHANGED
@@ -1,82 +1,180 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RaymondChou
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.19'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.19'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
45
|
- - "~>"
|
18
46
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
47
|
+
version: '1.10'
|
20
48
|
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
52
|
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
54
|
+
version: '1.10'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rake
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: '10.
|
61
|
+
version: '10.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.3'
|
34
76
|
type: :development
|
35
77
|
prerelease: false
|
36
78
|
version_requirements: !ruby/object:Gem::Requirement
|
37
79
|
requirements:
|
38
80
|
- - "~>"
|
39
81
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
82
|
+
version: '3.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.22'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.22'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
41
111
|
- !ruby/object:Gem::Dependency
|
42
112
|
name: minitest
|
43
113
|
requirement: !ruby/object:Gem::Requirement
|
44
114
|
requirements:
|
45
115
|
- - "~>"
|
46
116
|
- !ruby/object:Gem::Version
|
47
|
-
version: '5.
|
117
|
+
version: '5.8'
|
48
118
|
type: :development
|
49
119
|
prerelease: false
|
50
120
|
version_requirements: !ruby/object:Gem::Requirement
|
51
121
|
requirements:
|
52
122
|
- - "~>"
|
53
123
|
- !ruby/object:Gem::Version
|
54
|
-
version: '5.
|
124
|
+
version: '5.8'
|
55
125
|
description: Tencent Cloud Object Service Ruby SDK.
|
56
126
|
email:
|
57
127
|
- freezestart@gmail.com
|
58
|
-
executables:
|
128
|
+
executables:
|
129
|
+
- cos
|
59
130
|
extensions: []
|
60
131
|
extra_rdoc_files: []
|
61
132
|
files:
|
62
133
|
- ".gitignore"
|
63
|
-
- ".
|
64
|
-
- ".idea/cos.iml"
|
65
|
-
- ".idea/encodings.xml"
|
66
|
-
- ".idea/misc.xml"
|
67
|
-
- ".idea/modules.xml"
|
68
|
-
- ".idea/workspace.xml"
|
134
|
+
- ".rspec"
|
69
135
|
- ".travis.yml"
|
70
136
|
- Gemfile
|
137
|
+
- LICENSE
|
71
138
|
- README.md
|
72
139
|
- Rakefile
|
73
|
-
- bin/
|
140
|
+
- bin/cos
|
74
141
|
- bin/setup
|
75
142
|
- cos.gemspec
|
76
143
|
- lib/cos.rb
|
144
|
+
- lib/cos/api.rb
|
145
|
+
- lib/cos/bucket.rb
|
146
|
+
- lib/cos/checkpoint.rb
|
147
|
+
- lib/cos/client.rb
|
148
|
+
- lib/cos/config.rb
|
149
|
+
- lib/cos/dir.rb
|
150
|
+
- lib/cos/download.rb
|
151
|
+
- lib/cos/exception.rb
|
152
|
+
- lib/cos/file.rb
|
153
|
+
- lib/cos/http.rb
|
154
|
+
- lib/cos/logging.rb
|
155
|
+
- lib/cos/resource.rb
|
156
|
+
- lib/cos/signature.rb
|
157
|
+
- lib/cos/slice.rb
|
158
|
+
- lib/cos/struct.rb
|
159
|
+
- lib/cos/tree.rb
|
160
|
+
- lib/cos/util.rb
|
77
161
|
- lib/cos/version.rb
|
162
|
+
- spec/cos/bucket_spec.rb
|
163
|
+
- spec/cos/client_spec.rb
|
164
|
+
- spec/cos/dir_spec.rb
|
165
|
+
- spec/cos/download_spec.rb
|
166
|
+
- spec/cos/http_spec.rb
|
167
|
+
- spec/cos/signature_spec.rb
|
168
|
+
- spec/cos/slice_spec.rb
|
169
|
+
- spec/cos/struct_spec.rb
|
170
|
+
- spec/cos/tree_spec.rb
|
171
|
+
- spec/cos/util_spec.rb
|
172
|
+
- test/download_test.rb
|
173
|
+
- test/list_test.rb
|
174
|
+
- test/upload_test.rb
|
78
175
|
homepage: http://github.com/RaymondChou
|
79
|
-
licenses:
|
176
|
+
licenses:
|
177
|
+
- Apache 2.0
|
80
178
|
metadata: {}
|
81
179
|
post_install_message:
|
82
180
|
rdoc_options: []
|
@@ -86,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
184
|
requirements:
|
87
185
|
- - ">="
|
88
186
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
187
|
+
version: 1.9.3
|
90
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
189
|
requirements:
|
92
190
|
- - ">="
|
@@ -97,5 +195,18 @@ rubyforge_project:
|
|
97
195
|
rubygems_version: 2.4.5.1
|
98
196
|
signing_key:
|
99
197
|
specification_version: 4
|
100
|
-
summary: Tencent
|
101
|
-
test_files:
|
198
|
+
summary: Tencent COS Ruby SDK.
|
199
|
+
test_files:
|
200
|
+
- spec/cos/bucket_spec.rb
|
201
|
+
- spec/cos/client_spec.rb
|
202
|
+
- spec/cos/dir_spec.rb
|
203
|
+
- spec/cos/download_spec.rb
|
204
|
+
- spec/cos/http_spec.rb
|
205
|
+
- spec/cos/signature_spec.rb
|
206
|
+
- spec/cos/slice_spec.rb
|
207
|
+
- spec/cos/struct_spec.rb
|
208
|
+
- spec/cos/tree_spec.rb
|
209
|
+
- spec/cos/util_spec.rb
|
210
|
+
- test/download_test.rb
|
211
|
+
- test/list_test.rb
|
212
|
+
- test/upload_test.rb
|