bfs-gs 0.3.7 → 0.4.0

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: 3d2d0a63a07421fb4c5f1a92f17ea41691cfffce5b5c4bcf708d2fba02e33155
4
- data.tar.gz: 83e4ae9f78f3c5694f84920040e7b9c7de1ee5eaccabaffddf0747001aa27def
3
+ metadata.gz: 006a502518adf673cb33da4d3ce62db552755fea4a1756e6c26ab3247f64767e
4
+ data.tar.gz: 1c1a8266976872c3d658afbb3c44203a3e49e3c03e519a1001b455bcba1e6ee6
5
5
  SHA512:
6
- metadata.gz: 64844e32961bf6d3ec8c808347a050194be42d41014832ae86c16fba596b3ac48e0dcc50c635a9da0caa7130eb872c2929da323718546a415eae8648375bad2d
7
- data.tar.gz: a208ce6d19b0790059df252deee526b68a664f405a2e1ddd2ef2d1f9750f2366e3030657ecfcc7932654c0f9debb11b6beb3c9485f93675fae1b85b024f86618
6
+ metadata.gz: bd74e8cef26550517c999dfbb4402a2138e977f73b7935b9260e019bb0e633dd1687b618c0803eee24bef659d499d1a322da4b29b1b071542e216392bc407d0a
7
+ data.tar.gz: 7cc34c97ee1fae097db90698ea4f66fc99f73404065f154104a9249b7510d59215d29d18137421e69965d69cb19fb6793980f4ab813ab30e1d36f918a8ef85b9
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, encoding: opts.delete(:encoding)) 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,8 +115,11 @@ 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,
117
124
  credentials: params.key?('credentials') ? params['credentials'].first : nil,
118
125
  acl: params.key?('acl') ? params['acl'].first : nil,
@@ -29,9 +29,15 @@ RSpec.describe BFS::Bucket::GS, if: run_spec do
29
29
  it_behaves_like 'a bucket'
30
30
 
31
31
  it 'should resolve from URL' do
32
- bucket = BFS.resolve("gs://#{sandbox[:bucket]}?acl=private&project_id=#{sandbox[:project]}")
32
+ bucket = BFS.resolve("gs://#{sandbox[:bucket]}/?acl=private&project_id=#{sandbox[:project]}")
33
33
  expect(bucket).to be_instance_of(described_class)
34
34
  expect(bucket.name).to eq(sandbox[:bucket])
35
+ expect(bucket.instance_variable_get(:@prefix)).to be_nil
36
+
37
+ bucket = BFS.resolve("gs://#{sandbox[:bucket]}/a/b/")
38
+ expect(bucket).to be_instance_of(described_class)
39
+ expect(bucket.name).to eq(sandbox[:bucket])
40
+ expect(bucket.instance_variable_get(:@prefix)).to eq('a/b')
35
41
  end
36
42
 
37
43
  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.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-02 00:00:00.000000000 Z
11
+ date: 2019-06-17 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.7
19
+ version: 0.4.0
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.7
26
+ version: 0.4.0
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,14 +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
- rubygems_version: 3.0.2
70
+ rubygems_version: 3.0.3
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: GS bucket adapter for bfs