b2-client 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/b2.rb +3 -14
- data/lib/b2/bucket.rb +1 -27
- data/lib/b2/connection.rb +38 -0
- data/lib/b2/upload_chunker.rb +3 -3
- data/lib/b2/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd33ba10f4089d70caa9a3c857517300cc428a1589660bff8a99f87779bff547
|
4
|
+
data.tar.gz: 8a641aeaa454fb3313ef25b2eef2b8120b31874dbc0fb6afb9209bf5cfcabc66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16103376d13143f6606848a41f2aa4fafa31afec786b4b86dfc1c71e823cdacd692b4aa4b514ae7a5bdde52925ad3cb21fe57cbe6a241d0b375b5aa7cbdfef6f
|
7
|
+
data.tar.gz: df8e92a10236f6b0f7ae5b303cf262d8d30ad2d605398445b6b47fe65d038b206832e4286ccd234eefb97b82d01e9144df1ad7bcbef1bf819873f827f40217b7
|
data/lib/b2.rb
CHANGED
@@ -94,21 +94,10 @@ class B2
|
|
94
94
|
@connection.download_url + '/file/' + bucket + '/' + filename + "?Authorization=" + response['authorizationToken']
|
95
95
|
end
|
96
96
|
|
97
|
-
def download(bucket,
|
98
|
-
|
99
|
-
data = ""
|
100
|
-
|
101
|
-
@connection.get("/file/#{bucket}/#{filename}") do |response|
|
102
|
-
response.read_body do |chunk|
|
103
|
-
digestor << chunk
|
104
|
-
block.nil? ? (data << chunk) : block(chunk)
|
105
|
-
end
|
106
|
-
if digestor.hexdigest != resp['X-Bz-Content-Sha1']
|
107
|
-
raise 'file error'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
block.nil? ? data : nil
|
97
|
+
def download(bucket, key, to=nil, &block)
|
98
|
+
@connection.download(bucket, key, to, &block)
|
111
99
|
end
|
100
|
+
|
112
101
|
|
113
102
|
def download_to_file(bucket, key, filename)
|
114
103
|
file = File.open(filename, 'w')
|
data/lib/b2/bucket.rb
CHANGED
@@ -68,33 +68,7 @@ class B2
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def download(key, to=nil, &block)
|
71
|
-
|
72
|
-
data = ""
|
73
|
-
digestor = Digest::SHA1.new
|
74
|
-
|
75
|
-
uri = URI.parse(@connection.download_url)
|
76
|
-
conn = Net::HTTP.new(uri.host, uri.port)
|
77
|
-
conn.use_ssl = uri.scheme == 'https'
|
78
|
-
|
79
|
-
conn.get("/file/#{@name}/#{key}") do |response|
|
80
|
-
|
81
|
-
response.read_body do |chunk|
|
82
|
-
digestor << chunk
|
83
|
-
if to
|
84
|
-
to << chunk
|
85
|
-
elsif block
|
86
|
-
block(chunk)
|
87
|
-
else
|
88
|
-
data << chunk
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
if digestor.hexdigest != resp['X-Bz-Content-Sha1']
|
93
|
-
raise 'file error'
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
block.nil? && to.nil? ? data : nil
|
71
|
+
@connection.download(@name, key, to, &block)
|
98
72
|
end
|
99
73
|
|
100
74
|
def delete!(key)
|
data/lib/b2/connection.rb
CHANGED
@@ -83,6 +83,44 @@ class B2
|
|
83
83
|
return_value
|
84
84
|
end
|
85
85
|
|
86
|
+
def download(bucket, key, to=nil, &block)
|
87
|
+
to = ::File.open(to, 'wb') if to.is_a?(String)
|
88
|
+
digestor = Digest::SHA1.new
|
89
|
+
data = ""
|
90
|
+
|
91
|
+
uri = URI.parse(@download_url)
|
92
|
+
conn = Net::HTTP.new(uri.host, uri.port)
|
93
|
+
conn.use_ssl = uri.scheme == 'https'
|
94
|
+
|
95
|
+
req = Net::HTTP::Get.new("/file/#{bucket}/#{key}")
|
96
|
+
req['Authorization'] = authorization_token
|
97
|
+
conn.start do |http|
|
98
|
+
http.request(req) do |response|
|
99
|
+
case response
|
100
|
+
when Net::HTTPSuccess
|
101
|
+
response.read_body do |chunk|
|
102
|
+
digestor << chunk
|
103
|
+
if to
|
104
|
+
to << chunk
|
105
|
+
elsif block
|
106
|
+
block(chunk)
|
107
|
+
else
|
108
|
+
data << chunk
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if digestor.hexdigest != response['X-Bz-Content-Sha1']
|
113
|
+
raise 'file error'
|
114
|
+
end
|
115
|
+
else
|
116
|
+
raise response.body
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
block.nil? && to.nil? ? data : nil
|
122
|
+
end
|
123
|
+
|
86
124
|
def get(path, body=nil, &block)
|
87
125
|
request = Net::HTTP::Get.new(path)
|
88
126
|
|
data/lib/b2/upload_chunker.rb
CHANGED
@@ -6,10 +6,10 @@ class B2
|
|
6
6
|
@data = data
|
7
7
|
@sha_appended = false
|
8
8
|
@digestor = Digest::SHA1.new
|
9
|
-
@size = if data.is_a?(
|
10
|
-
data.size + 40
|
11
|
-
elsif data.is_a?(String)
|
9
|
+
@size = if data.is_a?(String)
|
12
10
|
data.bytesize + 40
|
11
|
+
else
|
12
|
+
data.size + 40
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
data/lib/b2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: b2-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|