bkblz 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e32fc4c015090ea1808daf2fa0bf5d6f69ee6362
4
- data.tar.gz: 39ab9e46da28e38ac44080d6b11b480d1d940ef5
3
+ metadata.gz: 5997f9298f8ca9a76ccab7d97a32056c39715284
4
+ data.tar.gz: 5705d4a980f24bc1129ea632e1d43c91a4141ebb
5
5
  SHA512:
6
- metadata.gz: e6454e5cc445133352b0b8c9b30e77b39aeffac724db4c49fe21fc7c9e45fbc6893b65b607ab2686cfbd36ce1b014da943fff0c289986b2ad3c0797c644fbe4c
7
- data.tar.gz: 2ed424c4099bc450e7adc719e1aa3ce26cbc8d7929cc6618e83719a73dd17d8f10140cbcd8185785f28e004e71430cf5649084d4ef56fcf0ee5777edaa2310c6
6
+ metadata.gz: ceb34167c6cac650642da332387d44dd413d5d16f96aaaa940b007ce412cf586640ce7e5770827c4d43e37a9f6e1013e79a499075c8ed47785de0ee1c2a1b5af
7
+ data.tar.gz: 756b93c8aafa321d6301e7bc5a1146dcbd64be52581de83c8ca16f41aea79ea6804d97bf6c4d2da35d53f0472611ad6453c5904b989382f658cd9778cb2ad3ca
data/bin/bkblz CHANGED
@@ -109,18 +109,26 @@ module Bkblz
109
109
  class File < Thor
110
110
  include Helper
111
111
 
112
- desc "upload <bucket_name> <local_file_path>", "upload a local file to B2"
112
+ desc "upload <bucket_name> <local_file_path>", "upload a local file to B2" +
113
+ " if <local_file_path> is \"-\" (0x2d), then upload will read from STDIN."
113
114
  option :file_name, :desc => "remote file name, if not given the basename" +
114
- "of the local file is used"
115
+ " of the local file is used"
115
116
  def upload(bucket_name, local_file_path)
116
117
  parse_opts
117
118
 
119
+ params = {
120
+ :bucket_name => bucket_name,
121
+ :file_name => options[:file_name]
122
+ }
123
+
124
+ if local_file_path == "-"
125
+ params[:file_body] = STDIN.read
126
+ else
127
+ params[:file_path] = local_file_path
128
+ end
129
+
118
130
  file_info = run_task do
119
- Bkblz::Task::UploadFile.run Bkblz.config, {
120
- :bucket_name => bucket_name,
121
- :file_path => local_file_path,
122
- :file_name => options[:file_name]
123
- }
131
+ Bkblz::Task::UploadFile.run Bkblz.config, params
124
132
  end
125
133
 
126
134
  print_header "File Info"
@@ -3,25 +3,41 @@ module Bkblz
3
3
  class UploadFile < BaseTask
4
4
 
5
5
  task_param :bucket_name, :required => true
6
- task_param :file_path, :required => true
6
+ task_param :file_body # Either file_body or file_path is required
7
+ task_param :file_path
7
8
  task_param :file_name # Overrides local file_path if given
8
9
 
9
- # TODO(erick): Change file_path to a byte string, let the task be agnostic
10
- # to where the data comes from. (Probably v0.2).
11
10
  def run_internal(session, params)
12
- f = ::File.new(params[:file_path], "r")
11
+ file_body = if params[:file_path]
12
+ f = ::File.new(params[:file_path], "r")
13
+ f.read
14
+ elsif params[:file_body]
15
+ params[:file_body]
16
+ else
17
+ raise 'missing either :file_body or :file_path param'
18
+ end
19
+
20
+ file_name = if params[:file_name]
21
+ params[:file_name]
22
+ elsif params[:file_path]
23
+ ::File.basename(params[:file_path])
24
+ else
25
+ raise 'missing either :file_name or :file_path param'
26
+ end
27
+
28
+ file_mtime = if params[:file_path]
29
+ ::File.mtime(params[:file_path])
30
+ else
31
+ Time.now
32
+ end.to_i * 1000
13
33
 
14
34
  bucket = find_bucket_by_name session, params[:bucket_name]
15
35
  upload_auth = session.send(
16
36
  Bkblz::V1::GetUploadUrlRequest.new bucket.bucket_id).to_model
17
37
 
18
- file_name = params[:file_name] || ::File.basename(f.path)
19
- file_body = f.read
20
- mtime_millis = f.mtime.to_i * 1000
21
-
22
38
  upload_file_info = session.send(
23
- Bkblz::V1::UploadFileRequest.new upload_auth, file_body, file_name,
24
- nil, mtime_millis).to_model
39
+ Bkblz::V1::UploadFileRequest.new(
40
+ upload_auth, file_body, file_name, nil, file_mtime)).to_model
25
41
  end
26
42
  end
27
43
  end
data/lib/bkblz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bkblz
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bkblz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erick Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-27 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor