blobs 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/blobs.rb +34 -6
- data/lib/blobs/version.rb +1 -1
- 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: 7a0547fdb6f1f10e38893fefeb4c22cda68f7af9
|
4
|
+
data.tar.gz: 0e463413c0e12530c667e2e6d9a0881dea725aa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31b1ca894800bb07f0d652b6cd7a0ce0bae89e168bed56f8b1dc4c15d303cf08783b79642d20642e0019a01ebf6f6fbe7ab8164b632ee3807c19b3e72aaeaa48
|
7
|
+
data.tar.gz: f6926857bdfd68dd090d5b86b7001cf241e1da6008baef3c1ba0fc93facc3e9d8d88b5754cf33b3191dc997882011c1475a2878ee5435aa146542584ff6f9783
|
data/README.md
CHANGED
@@ -31,6 +31,9 @@ Or install it yourself as:
|
|
31
31
|
c.destroy(blob_id)
|
32
32
|
c.all
|
33
33
|
|
34
|
+
c.add_dir("/Users/oliver/Downloads")
|
35
|
+
c.get_dir("/Users/oliver/Downloads")
|
36
|
+
|
34
37
|
## Development
|
35
38
|
|
36
39
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/blobs.rb
CHANGED
@@ -154,10 +154,21 @@ module Blobs
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
def add_file(file_path, key = 'default')
|
157
|
+
def add_file(file_path, key = 'default', persist_locally = false)
|
158
158
|
raise 'No file path given!' unless file_path
|
159
159
|
raise "File doesn't exist!" unless File.file?(file_path)
|
160
|
-
|
160
|
+
file_json = file_to_json(file_path)
|
161
|
+
resp = create(file_json, key, true)
|
162
|
+
if persist_locally
|
163
|
+
if resp['id']
|
164
|
+
File.open("#{file_path.gsub(file_json[:file_name], resp['id'])}.blob", 'wb') do |f|
|
165
|
+
f.write(Base64.encode64(file_json.to_json))
|
166
|
+
f.close
|
167
|
+
end
|
168
|
+
else
|
169
|
+
raise "No blob id for file: #{file_json[:file_name]}"
|
170
|
+
end
|
171
|
+
end
|
161
172
|
resp ? resp['id'] : nil
|
162
173
|
end
|
163
174
|
|
@@ -174,16 +185,18 @@ module Blobs
|
|
174
185
|
nil
|
175
186
|
end
|
176
187
|
|
177
|
-
def add_dir(base_path, rm = false)
|
188
|
+
def add_dir(base_path, rm = false, persist_locally = false)
|
178
189
|
raise 'No base path given!' unless base_path
|
179
190
|
blob_ids = []
|
180
191
|
Dir["#{base_path}/**/*.*"].each do |file|
|
181
192
|
key = file.split('/')[0...-1].join('/')
|
182
193
|
log("Adding file: #{file}")
|
183
194
|
log("Key: #{key}")
|
184
|
-
|
185
|
-
|
186
|
-
|
195
|
+
unless file.include?('.blob')
|
196
|
+
if (blob_id = add_file(file, key, persist_locally))
|
197
|
+
blob_ids << blob_id
|
198
|
+
File.delete(file) if rm
|
199
|
+
end
|
187
200
|
end
|
188
201
|
end
|
189
202
|
blob_ids
|
@@ -205,6 +218,21 @@ module Blobs
|
|
205
218
|
files
|
206
219
|
end
|
207
220
|
|
221
|
+
def restore_local_dir(base_path, rm = false)
|
222
|
+
files = []
|
223
|
+
Dir["#{base_path}/**/*.*"].each do |file|
|
224
|
+
if file.include?('.blob')
|
225
|
+
decoded_string = Base64.decode64(File.open(file, 'rb').read)
|
226
|
+
file_json = JSON.parse(decoded_string)
|
227
|
+
dir = file.split('/')[0...-1].join('/')
|
228
|
+
file_from_json(file_json, dir)
|
229
|
+
files << "#{dir}/#{file_json['file_name']}"
|
230
|
+
File.delete(file) if rm
|
231
|
+
end
|
232
|
+
end
|
233
|
+
files
|
234
|
+
end
|
235
|
+
|
208
236
|
private
|
209
237
|
def headers(additional_headers = {})
|
210
238
|
additional_headers.merge({
|
data/lib/blobs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Kiessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|