bkblz 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 990022a090baa3a510ff31ed662426b951a73245
4
- data.tar.gz: 531dfaecf56ea2a1c886352d4725a0e9558c4c06
3
+ metadata.gz: abe5867c43969a879ab33dddea87ff9986038150
4
+ data.tar.gz: f8f0c5b4fc7246c59f659d81d28a52141a90cadc
5
5
  SHA512:
6
- metadata.gz: e1244c37357c5fa5c0c183efedb218683c854002b60f6b4abb976f3b9c033c1f189ff0bbf30d4216189a5678ccc55cb05af4abac6d1bf827fc0c2646eb5c9160
7
- data.tar.gz: bf64f19457e1d9b21b12298b7c4756b540b812964fadca488639410aa5f8f3749a6acb1d236476f350f69e3864df7fdcd32694d0d562877239821d4b64a2bf1a
6
+ metadata.gz: 69029a01ede66b67bd7f7052409516f53a3a476ecbac939d9c12b43462e4df0cfcb930ae1382e1dbe716aab51627ac855e5b4dc532ef44bc4642eb053db204ee
7
+ data.tar.gz: 72d0a93f4465a0a3966195d9dab106ee30eb873032a720d845eaafa5c0ce3b8b886dcb440f891a768619c89d7363e3a56a734bf46eecc1fa35be52b045842273
data/README.rb CHANGED
@@ -9,6 +9,7 @@ Currently the gem supports the following V1 API calls:
9
9
  * b2_create_bucket
10
10
  * b2_delete_bucket
11
11
  * b2_delete_file_version
12
+ * b2_get_file_info
12
13
  * b2_list_buckets
13
14
  * b2_list_file_names
14
15
  * b2_list_file_versions
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 <id>", "displays info for file with <id>"
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 => options[:id]
148
+ :file_id => file_id
135
149
  }
136
150
  end
137
151
 
@@ -2,6 +2,7 @@ require_relative "task_helpers"
2
2
  require_relative "task"
3
3
 
4
4
  require_relative "create_bucket"
5
+ require_relative "download_file"
5
6
  require_relative "get_file_info"
6
7
  require_relative "list_buckets"
7
8
  require_relative "list_files"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Bkblz
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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.5
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