bfs-gs 0.3.5 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bfs-gs.gemspec +2 -2
- data/lib/bfs/bucket/gs.rb +14 -6
- data/spec/bfs/bucket/gs_spec.rb +9 -2
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb617f85d661ff62241a6cdb341a1e2a049718f05b6387ac712d643c98f37411
|
4
|
+
data.tar.gz: 4055f79b180285672256b0bddac2ad3a95a02f41146139aa49fda1e0fd84a3b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ce3d3cca1b171fb9d02c43010bbff0b30e39516f1fdb97093cfadc2b58ab39a2152c5d380690469aa8fcfe396d3d1ca4dba2705a1ea3f49846011fa591a15b
|
7
|
+
data.tar.gz: 908a0dd616fcbb52f4f0de5df486c95e86d9c84a4be43e243b06c4852c11357ee89fd6524d52492017b21e09d92915f9a310c86964543458d131222dc908b965
|
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.
|
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
|
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
|
-
|
67
|
-
|
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),
|
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,
|
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
|
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
|
data/spec/bfs/bucket/gs_spec.rb
CHANGED
@@ -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]}
|
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.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-18 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.
|
19
|
+
version: 0.4.2
|
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.
|
26
|
+
version: 0.4.2
|
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: '
|
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: '
|
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.
|
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
|
-
|
71
|
-
rubygems_version: 2.7.6
|
70
|
+
rubygems_version: 3.0.3
|
72
71
|
signing_key:
|
73
72
|
specification_version: 4
|
74
73
|
summary: GS bucket adapter for bfs
|