bkblz 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rb +1 -0
- data/bin/bkblz +17 -3
- data/lib/bkblz/task/all.rb +1 -0
- data/lib/bkblz/task/download_file.rb +42 -0
- data/lib/bkblz/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abe5867c43969a879ab33dddea87ff9986038150
|
4
|
+
data.tar.gz: f8f0c5b4fc7246c59f659d81d28a52141a90cadc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69029a01ede66b67bd7f7052409516f53a3a476ecbac939d9c12b43462e4df0cfcb930ae1382e1dbe716aab51627ac855e5b4dc532ef44bc4642eb053db204ee
|
7
|
+
data.tar.gz: 72d0a93f4465a0a3966195d9dab106ee30eb873032a720d845eaafa5c0ce3b8b886dcb440f891a768619c89d7363e3a56a734bf46eecc1fa35be52b045842273
|
data/README.rb
CHANGED
data/bin/bkblz
CHANGED
@@ -91,6 +91,21 @@ module Bkblz
|
|
91
91
|
print_model file_info
|
92
92
|
end
|
93
93
|
|
94
|
+
desc "file download <id> <dir>", "downloads file <id> to directory <dir>"
|
95
|
+
def download(file_id, dir_path)
|
96
|
+
parse_opts
|
97
|
+
|
98
|
+
file_info = run_task do
|
99
|
+
Bkblz::Task::DownloadFile.run Bkblz.config, {
|
100
|
+
:file_id => file_id,
|
101
|
+
:dir_path => dir_path
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
print_header "File Info"
|
106
|
+
print_model file_info
|
107
|
+
end
|
108
|
+
|
94
109
|
desc "file list <bucket_name>", "lists files in a bucket"
|
95
110
|
option :start_at, :desc => "file name to start listing from, cannot be used with --all"
|
96
111
|
option :limit, {
|
@@ -124,14 +139,13 @@ module Bkblz
|
|
124
139
|
end
|
125
140
|
end
|
126
141
|
|
127
|
-
desc "file info <
|
128
|
-
option :id, :desc => "the file id as returned by <file list>"
|
142
|
+
desc "file info <file_id>", "displays info for file with <id>"
|
129
143
|
def info(file_id)
|
130
144
|
parse_opts
|
131
145
|
|
132
146
|
file_info = run_task do
|
133
147
|
Bkblz::Task::GetFileInfo.run Bkblz.config, {
|
134
|
-
:file_id =>
|
148
|
+
:file_id => file_id
|
135
149
|
}
|
136
150
|
end
|
137
151
|
|
data/lib/bkblz/task/all.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module Bkblz
|
4
|
+
module Task
|
5
|
+
class DownloadFile < BaseTask
|
6
|
+
|
7
|
+
task_param :file_id, :required => true
|
8
|
+
task_param :dir_path, :required => true
|
9
|
+
|
10
|
+
def run_internal(session, params)
|
11
|
+
partial_file_info =
|
12
|
+
Bkblz::V1::Model::PartialFileInfo.new :file_id => params[:file_id]
|
13
|
+
download_file_info = session.send(
|
14
|
+
Bkblz::V1::DownloadFileByIdRequest.new partial_file_info).to_model
|
15
|
+
|
16
|
+
unless download_file_info.sha1 == Digest::SHA1.hexdigest(download_file_info.body)
|
17
|
+
raise "invalid checksum"
|
18
|
+
end
|
19
|
+
|
20
|
+
dir_path = params[:dir_path]
|
21
|
+
unless ::File.directory? dir_path
|
22
|
+
raise "dir_path is not a directory: %s" % dir_path
|
23
|
+
end
|
24
|
+
unless ::File.writable?(dir_path)
|
25
|
+
raise "unable to write to directory %s" % dir_path
|
26
|
+
end
|
27
|
+
|
28
|
+
f_path = ::File.join dir_path, download_file_info.file_name
|
29
|
+
if ::File.exists?(f_path) && !::File.writable?(f_path)
|
30
|
+
raise "unable to write to existing file: %s" % f_path
|
31
|
+
end
|
32
|
+
|
33
|
+
::File.binwrite(f_path, download_file_info.body)
|
34
|
+
|
35
|
+
# This can be expensive, we're momentarily copying the body
|
36
|
+
map = download_file_info.to_map
|
37
|
+
map[:body] = "<omitted>"
|
38
|
+
Bkblz::V1::Model::FileDownload.new map
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/bkblz/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bkblz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erick Johnson
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/bkblz/map_key_formatter.rb
|
92
92
|
- lib/bkblz/task/all.rb
|
93
93
|
- lib/bkblz/task/create_bucket.rb
|
94
|
+
- lib/bkblz/task/download_file.rb
|
94
95
|
- lib/bkblz/task/get_file_info.rb
|
95
96
|
- lib/bkblz/task/list_buckets.rb
|
96
97
|
- lib/bkblz/task/list_files.rb
|