fastdfs-client 1.2.0 → 1.3.0
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/.DS_Store +0 -0
- data/README.md +2 -0
- data/lib/fastdfs-client/client_proxy.rb +1 -1
- data/lib/fastdfs-client/extend_core.rb +28 -0
- data/lib/fastdfs-client/socket.rb +3 -1
- data/lib/fastdfs-client/storage.rb +6 -7
- data/lib/fastdfs-client/utils.rb +0 -7
- data/lib/fastdfs-client/version.rb +1 -1
- data/spec/.DS_Store +0 -0
- data/spec/mock_tcp_socket.rb +2 -1
- data/spec/storage_spec.rb +42 -27
- data/spec/tracker_spec.rb +10 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e0b3352eb6ff6a305d8083b19000e950632c6db
|
4
|
+
data.tar.gz: 80788d168fa8726c71cf8da1f9ef325e145da3c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e4a2a249cd266bcac2fe453f7a0120f53589a006328a355b78475016ec91facb337c4d965164f872bcd188744c09dde55474d82810c26f400eaf57760fc0368
|
7
|
+
data.tar.gz: e555aba138f34c8088a3709e5426426a79bab48fea3edba8b033d89418bf1e2c9c477300ff1caafe5c7815f1ef21b6acc83bdf666fabd965c6799d71647f5b13
|
data/.DS_Store
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ module Fastdfs
|
|
22
22
|
@socket.connection do
|
23
23
|
full_header = ProtoCommon.header_bytes(cmd, content_len) + header
|
24
24
|
@socket.write(cmd, full_header)
|
25
|
-
Array(
|
25
|
+
Array(content).each do |c|
|
26
26
|
@socket.write(cmd, c)
|
27
27
|
end
|
28
28
|
@socket.receive &block
|
@@ -7,4 +7,32 @@ class Array
|
|
7
7
|
def full_fill(val, len)
|
8
8
|
self.fill(val, self.length...len)
|
9
9
|
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
class NilClass
|
14
|
+
def blank?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class String
|
20
|
+
def blank?
|
21
|
+
self.strip.empty?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Object
|
26
|
+
def blank?
|
27
|
+
respond_to?(:empty?) ? empty? : !self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
class Hash
|
33
|
+
|
34
|
+
def fs_symbolize_keys
|
35
|
+
defined?(super) ? super : self.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
36
|
+
end
|
37
|
+
|
10
38
|
end
|
@@ -19,8 +19,10 @@ module Fastdfs
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def write(*args)
|
22
|
+
debugger if args[1] == 119
|
22
23
|
@cmd = args.shift
|
23
24
|
pkg = args.shift
|
25
|
+
|
24
26
|
pkg = pkg.pack("C*") if pkg.is_a?(Array)
|
25
27
|
@socket.write pkg
|
26
28
|
end
|
@@ -89,7 +91,7 @@ module Fastdfs
|
|
89
91
|
body_len -= len
|
90
92
|
end
|
91
93
|
end
|
92
|
-
@content = nil if
|
94
|
+
@content = nil if @content.blank?
|
93
95
|
end
|
94
96
|
|
95
97
|
end
|
@@ -18,7 +18,7 @@ module Fastdfs
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def upload(file, options = {})
|
21
|
-
ext_name_bs = File.extname(file)[1
|
21
|
+
ext_name_bs = File.extname(file)[1..@extname_len].to_s.bytes.full_fill(0, @extname_len)
|
22
22
|
size_byte = ([@store_path] + Utils.number_to_buffer(file.size)).full_fill(0, @size_len)
|
23
23
|
content_len = (@size_len + @extname_len + file.size)
|
24
24
|
|
@@ -26,7 +26,7 @@ module Fastdfs
|
|
26
26
|
group_name_max_len = ProtoCommon::GROUP_NAME_MAX_LEN
|
27
27
|
|
28
28
|
res = {group_name: body[0...group_name_max_len].strip, path: body[group_name_max_len..-1]}
|
29
|
-
_set_metadata(res[:path], res[:group_name], options) unless
|
29
|
+
_set_metadata(res[:path], res[:group_name], options) unless options.blank?
|
30
30
|
res
|
31
31
|
end
|
32
32
|
end
|
@@ -42,7 +42,7 @@ module Fastdfs
|
|
42
42
|
res = body.split(ProtoCommon::RECORD_SEPERATOR).map do |c|
|
43
43
|
c.split(ProtoCommon::FILE_SEPERATOR)
|
44
44
|
end.flatten
|
45
|
-
|
45
|
+
Hash[*res].fs_symbolize_keys
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -74,8 +74,8 @@ module Fastdfs
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def extract_path!(path, group_name = nil)
|
77
|
-
raise "path arguments is empty!" if
|
78
|
-
if
|
77
|
+
raise "path arguments is empty!" if path.blank?
|
78
|
+
if group_name.blank?
|
79
79
|
group_name = /^\/?(\w+)/.match(path)[1]
|
80
80
|
path = path.gsub(Regexp.new("/?#{group_name}/?"), "")
|
81
81
|
end
|
@@ -90,8 +90,7 @@ module Fastdfs
|
|
90
90
|
size_bytes = Utils.number_to_buffer(path_bytes.length) + Utils.number_to_buffer(meta_bytes.length)
|
91
91
|
size_bytes = (size_bytes).full_fill(0, 16)
|
92
92
|
total = size_bytes.length + flag.length + group_bytes.length + path_bytes.length + meta_bytes.length
|
93
|
-
|
94
|
-
@proxy.dispose(CMD::SET_METADATA, total, (size_bytes + flag.bytes + group_bytes + path_bytes), meta_bytes)
|
93
|
+
@proxy.dispose(CMD::SET_METADATA, total, (size_bytes + flag.bytes + group_bytes + path_bytes), meta_bytes.pack("C*"))
|
95
94
|
end
|
96
95
|
|
97
96
|
def convert_meta_flag(flag)
|
data/lib/fastdfs-client/utils.rb
CHANGED
data/spec/.DS_Store
CHANGED
Binary file
|
data/spec/mock_tcp_socket.rb
CHANGED
data/spec/storage_spec.rb
CHANGED
@@ -25,38 +25,53 @@ describe Fastdfs::Client::Storage do
|
|
25
25
|
storage.upload(TestConfig::FILE, {author: "kaka", width: "800"})
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
expect(
|
28
|
+
it "tempfile upload " do
|
29
|
+
file = Tempfile.new("1.txt")
|
30
|
+
file.write("testtest")
|
31
|
+
file.close
|
32
|
+
expect(storage.upload(file)[:status]).to be_truthy
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
res = storage.upload(TestConfig::FILE)[:result]
|
37
|
-
storage.delete(res[:path], res[:group_name])
|
38
|
-
end
|
35
|
+
describe "upload file test " do
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
MockTCPSocket.any_instance.stub("recv").and_return(result.pack("C*"))
|
44
|
-
expect( storage.delete("fdsaf", res[:group_name])[:status] ).to be_falsey
|
45
|
-
end
|
37
|
+
before(:each) do
|
38
|
+
@res_body = storage.upload(TestConfig::FILE)
|
39
|
+
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
it "should the result attributes group_name and path" do
|
42
|
+
expect(@res_body[:status]).to be_truthy
|
43
|
+
expect(@res_body[:result]).to include(:group_name)
|
44
|
+
expect(@res_body[:result]).to include(:path)
|
45
|
+
end
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
it "can delete file by group and path" do
|
48
|
+
res = @res_body[:result]
|
49
|
+
storage.delete(res[:path], res[:group_name])
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can delete file raise exception" do
|
53
|
+
res = @res_body[:result]
|
54
|
+
result = FC::ProtoCommon.header_bytes(FC::CMD::RESP_CODE, 0, 22)
|
55
|
+
MockTCPSocket.any_instance.stub("recv").and_return(result.pack("C*"))
|
56
|
+
expect( storage.delete("fdsaf", res[:group_name])[:status] ).to be_falsey
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can get metadata results" do
|
60
|
+
res = @res_body[:result]
|
61
|
+
storage.set_metadata(res[:path], res[:group_name], TestConfig::METADATA)
|
62
|
+
res = storage.get_metadata("#{res[:group_name]}/#{res[:path]}")
|
63
|
+
expect(res[:result]).to eq(TestConfig::METADATA)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "can set metadata" do
|
67
|
+
expect(storage.set_metadata(TestConfig::FILE_NAME, TestConfig::GROUP_NAME, TestConfig::METADATA)).to be_truthy
|
68
|
+
end
|
55
69
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
it "download the file to the local" do
|
71
|
+
res = storage.download(TestConfig::FILE_NAME, TestConfig::GROUP_NAME)
|
72
|
+
expect(res[:status]).to be_truthy
|
73
|
+
expect(res[:result]).to be_an_instance_of(Tempfile)
|
74
|
+
expect(IO.read(res[:result])).to eq(IO.read(TestConfig::FILE))
|
75
|
+
end
|
61
76
|
end
|
62
77
|
end
|
data/spec/tracker_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe Fastdfs::Client::Tracker do
|
|
24
24
|
|
25
25
|
it "verify the server address and port" do
|
26
26
|
expect(tracker.get_storage.socket.host).to eq(TestConfig::STORAGE_IP)
|
27
|
-
|
27
|
+
|
28
28
|
expect(tracker.get_storage.socket.port.to_s).to eq(TestConfig::STORAGE_PORT)
|
29
29
|
expect(tracker.get_storage.store_path).to eq(TestConfig::STORE_PATH)
|
30
30
|
end
|
@@ -36,22 +36,19 @@ describe Fastdfs::Client::Tracker do
|
|
36
36
|
expect(tracker.get_storage[:status]).to be_falsey
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
40
|
-
items =
|
39
|
+
it "multi thread upload" do
|
40
|
+
items = 6.times.map do
|
41
41
|
Thread.new do
|
42
42
|
storage = tracker.get_storage
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
res = storage.upload(File.open(File.expand_path("../page.png", __FILE__)))
|
44
|
+
expect(res[:status]).to be_truthy
|
45
|
+
results = res[:result]
|
46
|
+
results = storage.delete(results[:path], results[:group_name])
|
47
|
+
expect(res[:status]).to be_truthy
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
items.
|
50
|
-
|
51
|
-
# storage = tracker.get_storage
|
52
|
-
# puts "#{storage.host}, #{storage.port}"
|
53
|
-
# results = storage.upload(File.open("page.png"))
|
54
|
-
# puts results
|
55
|
-
# puts storage.delete(results[:path], results[:group_name])
|
51
|
+
items.map{|item| item.join }
|
56
52
|
end
|
53
|
+
|
57
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastdfs-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ka Ka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|