bfs-gs 0.3.6 → 0.4.3

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
  SHA256:
3
- metadata.gz: a3d8fc13a0c3b0d63cfa1a205772932f829812920263b4ad641795c28fa65455
4
- data.tar.gz: 18f7032d23c3a149e9553767316b864725958dde8434b08c533e29883ef96a83
3
+ metadata.gz: b4159d1f71708e97bbc8305a18e671cd8c875908b23b907009d2e23ad3da2c14
4
+ data.tar.gz: 8700ac725661a73623efea456c0ed3c41cf452352c06edc93855daa21586d046
5
5
  SHA512:
6
- metadata.gz: 64a6fe4a1e2bab1c175290ee225002811450ba09b713fcbe03e1185fd40f55f537751cbf778ecae924c76de4de2f64d7e0604a3eeb697ec4ca86d58706668587
7
- data.tar.gz: fc2ae2ada39b91504672f22bd949a27649bd143baf13f06aabdeb93a62577ad44f56bfec5a70b262ca14ad43e7746ce6f1a0144ded688adb14c29ea00018cc9f
6
+ metadata.gz: 3150b437e030322aa18f9ec5eeaa5365658a9e15ad854c7e38b0a8b3ca8cbe0621251343cf3d920b1e4f5933cc6e4e19b90df0fe1003b585e63172e417ef4064
7
+ data.tar.gz: fc84d5ac79ae6999e25361ac208945aae929704c2401a7d6bf322c5c1110d0baf199061e155e6bf97ee3e88cfcadd9d45b59cbada9ed327fd3bbd092c8716d74
data/bfs-gs.gemspec CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- spec/*`.split("\n")
17
17
  s.require_paths = ['lib']
18
- s.required_ruby_version = '>= 2.2.0'
18
+ s.required_ruby_version = '>= 2.4.0'
19
19
 
20
20
  s.add_dependency 'bfs', s.version
21
- s.add_dependency 'google-cloud-storage'
21
+ s.add_dependency 'google-cloud-storage', '~> 1.18'
22
22
  end
data/lib/bfs/bucket/gs.rb CHANGED
@@ -12,7 +12,7 @@ module BFS
12
12
  #
13
13
  # @param [String] name the bucket name.
14
14
  # @param [Hash] opts options.
15
- # @option opts [String] :project_id project ID. Defaults to GCP_PROJECT env var. Required.
15
+ # @option opts [String] :project_id project ID. Defaults to GCP_PROJECT env var.
16
16
  # @option opts [String, Hash, Google::Auth::Credentials] :credentials
17
17
  # the path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object.
18
18
  # @option opts [String] :prefix custom namespace within the bucket
@@ -20,12 +20,14 @@ module BFS
20
20
  # @option opts [Integer] :timeout request timeout, in seconds.
21
21
  # @option opts [String] :acl set the default ACL.
22
22
  # @option opts [Google::Cloud::Storage] :client custom client.
23
+ # @option opts [String] :encoding default encoding to use, default: 'binary'
23
24
  def initialize(name, opts={})
24
25
  opts = opts.dup
25
26
  opts.keys.each do |key|
26
27
  val = opts.delete(key)
27
28
  opts[key.to_sym] = val unless val.nil?
28
29
  end
30
+ super(opts)
29
31
 
30
32
  @prefix = opts.delete(:prefix)
31
33
  acl = opts.delete(:acl)
@@ -63,8 +65,9 @@ module BFS
63
65
  # Creates a new file and opens it for writing
64
66
  def create(path, opts={}, &block)
65
67
  path = full_path(path)
66
- temp = BFS::TempWriter.new(path) do |t|
67
- File.open(t, binmode: true) do |file|
68
+ enc = opts.delete(:encoding) || @encoding
69
+ temp = BFS::TempWriter.new(path, encoding: enc) do |t|
70
+ File.open(t, encoding: enc) do |file|
68
71
  @bucket.create_file(file, path, opts)
69
72
  end
70
73
  end
@@ -80,21 +83,22 @@ module BFS
80
83
  # Opens an existing file for reading
81
84
  def open(path, opts={}, &block)
82
85
  path = full_path(path)
86
+ enc = opts.delete(:encoding) || @encoding
83
87
  file = @bucket.file(path)
84
88
  raise BFS::FileNotFound, trim_prefix(path) unless file
85
89
 
86
- temp = Tempfile.new(File.basename(path), binmode: true)
90
+ temp = Tempfile.new(File.basename(path), encoding: enc)
87
91
  temp.close
88
92
  file.download temp.path, opts
89
93
 
90
- File.open(temp.path, binmode: true, &block)
94
+ File.open(temp.path, encoding: enc, &block)
91
95
  end
92
96
 
93
97
  # Deletes a file.
94
98
  def rm(path, opts={})
95
99
  path = full_path(path)
96
100
  file = @bucket.file(path)
97
- file.delete(opts) if file
101
+ file&.delete(opts)
98
102
  end
99
103
 
100
104
  # Copies a file.
@@ -111,9 +115,13 @@ end
111
115
 
112
116
  BFS.register('gs') do |url|
113
117
  params = CGI.parse(url.query.to_s)
118
+ prefix = BFS.norm_path(params.key?('prefix') ? params['prefix'].first : url.path)
119
+ prefix = nil if prefix.empty?
114
120
 
115
121
  BFS::Bucket::GS.new url.host,
122
+ prefix: prefix,
116
123
  project_id: params.key?('project_id') ? params['project_id'].first : nil,
124
+ credentials: params.key?('credentials') ? params['credentials'].first : nil,
117
125
  acl: params.key?('acl') ? params['acl'].first : nil,
118
126
  timeout: params.key?('timeout') ? params['timeout'].first.to_i : nil,
119
127
  retries: params.key?('retries') ? params['retries'].first.to_i : nil
@@ -11,7 +11,8 @@ run_spec = \
11
11
  begin
12
12
  s = Google::Cloud::Storage.new(project_id: sandbox[:project])
13
13
  !s.bucket(sandbox[:bucket]).nil?
14
- rescue Signet::AuthorizationError
14
+ rescue Signet::AuthorizationError => e
15
+ warn "WARNING: unable to run #{File.basename __FILE__}: #{e.message}"
15
16
  false
16
17
  end
17
18
 
@@ -29,9 +30,15 @@ RSpec.describe BFS::Bucket::GS, if: run_spec do
29
30
  it_behaves_like 'a bucket'
30
31
 
31
32
  it 'should resolve from URL' do
32
- bucket = BFS.resolve("gs://#{sandbox[:bucket]}?acl=private&project_id=#{sandbox[:project]}")
33
+ bucket = BFS.resolve("gs://#{sandbox[:bucket]}/?acl=private&project_id=#{sandbox[:project]}")
33
34
  expect(bucket).to be_instance_of(described_class)
34
35
  expect(bucket.name).to eq(sandbox[:bucket])
36
+ expect(bucket.instance_variable_get(:@prefix)).to be_nil
37
+
38
+ bucket = BFS.resolve("gs://#{sandbox[:bucket]}/a/b/")
39
+ expect(bucket).to be_instance_of(described_class)
40
+ expect(bucket.name).to eq(sandbox[:bucket])
41
+ expect(bucket.instance_variable_get(:@prefix)).to eq('a/b')
35
42
  end
36
43
 
37
44
  it 'should enumerate over a large number of files' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfs-gs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-07 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bfs
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.6
19
+ version: 0.4.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.6
26
+ version: 0.4.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: google-cloud-storage
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.18'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.18'
41
41
  description: https://github.com/bsm/bfs.rb
42
42
  email: dimitrij@blacksquaremedia.com
43
43
  executables: []
@@ -60,15 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 2.2.0
63
+ version: 2.4.0
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubyforge_project:
71
- rubygems_version: 2.7.7
70
+ rubygems_version: 3.0.3
72
71
  signing_key:
73
72
  specification_version: 4
74
73
  summary: GS bucket adapter for bfs