bfs-gs 0.4.4 → 0.6.2
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 +4 -4
- data/bfs-gs.gemspec +1 -1
- data/lib/bfs/bucket/gs.rb +27 -32
- data/spec/bfs/bucket/gs_spec.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3945c75293459554de992abd3feb7f5e67dc37f4c85277aed1a00e25fc6f12
|
4
|
+
data.tar.gz: f8f4de972d679ec3bd44bfff8c4cfaef30b7fb3f864b28eaa366df3d1ff28007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06bc1b3093aad6a6be0dcdbfd7c17ed10d3121c5785b1aaa8ce12460ef40df05d26cdd3ba47d149d9e91ca9445cc38456b70abe17af87db023490959cd98959f
|
7
|
+
data.tar.gz: 4c6e3a77f3c0c63fa1e7eafb58c5ddb585984fbdc76b5960ab96e2ceff2a147df3f48bd9f8dbcfe66a45718a6411b0d21c1bd7dea1f005f81e338b7d4b7acf82
|
data/bfs-gs.gemspec
CHANGED
@@ -15,7 +15,7 @@ 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.5.0'
|
19
19
|
|
20
20
|
s.add_dependency 'bfs', s.version
|
21
21
|
s.add_dependency 'google-cloud-storage', '~> 1.18'
|
data/lib/bfs/bucket/gs.rb
CHANGED
@@ -20,18 +20,12 @@ 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
|
24
|
-
def initialize(name, opts
|
25
|
-
opts
|
26
|
-
opts.keys.each do |key|
|
27
|
-
val = opts.delete(key)
|
28
|
-
opts[key.to_sym] = val unless val.nil?
|
29
|
-
end
|
30
|
-
super(opts)
|
23
|
+
# @option opts [String] :encoding Custom encoding.
|
24
|
+
def initialize(name, prefix: nil, acl: nil, client: nil, **opts)
|
25
|
+
super(**opts)
|
31
26
|
|
32
|
-
@prefix =
|
33
|
-
|
34
|
-
client = opts.delete(:client) || Google::Cloud::Storage.new(opts)
|
27
|
+
@prefix = prefix
|
28
|
+
client ||= Google::Cloud::Storage.new(**opts)
|
35
29
|
|
36
30
|
@name = name.to_s
|
37
31
|
@bucket = client.bucket(@name)
|
@@ -39,13 +33,13 @@ module BFS
|
|
39
33
|
end
|
40
34
|
|
41
35
|
# Lists the contents of a bucket using a glob pattern
|
42
|
-
def ls(pattern='**/*', opts
|
36
|
+
def ls(pattern = '**/*', **opts)
|
43
37
|
prefix = pattern[%r{^[^\*\?\{\}\[\]]+/}]
|
44
38
|
prefix = File.join(*[@prefix, prefix].compact) if @prefix
|
45
39
|
opts = opts.merge(prefix: prefix) if prefix
|
46
40
|
|
47
41
|
Enumerator.new do |y|
|
48
|
-
@bucket.files(opts).all do |file|
|
42
|
+
@bucket.files(**opts).all do |file|
|
49
43
|
name = trim_prefix(file.name)
|
50
44
|
y << name if File.fnmatch?(pattern, name, File::FNM_PATHNAME)
|
51
45
|
end
|
@@ -53,22 +47,23 @@ module BFS
|
|
53
47
|
end
|
54
48
|
|
55
49
|
# Info returns the object info
|
56
|
-
def info(path, _opts
|
50
|
+
def info(path, **_opts)
|
57
51
|
path = full_path(path)
|
58
52
|
file = @bucket.file(path)
|
59
53
|
raise BFS::FileNotFound, trim_prefix(path) unless file
|
60
54
|
|
61
55
|
name = trim_prefix(file.name)
|
62
|
-
BFS::FileInfo.new(name, file.size, file.updated_at.to_time, file.content_type, file.metadata)
|
56
|
+
BFS::FileInfo.new(path: name, size: file.size, mtime: file.updated_at.to_time, content_type: file.content_type, metadata: norm_meta(file.metadata))
|
63
57
|
end
|
64
58
|
|
65
59
|
# Creates a new file and opens it for writing
|
66
|
-
def create(path, opts
|
60
|
+
def create(path, encoding: nil, perm: nil, **opts, &block)
|
61
|
+
opts[:metadata] = norm_meta(opts[:metadata])
|
67
62
|
path = full_path(path)
|
68
|
-
enc =
|
69
|
-
temp = BFS::TempWriter.new(path, encoding: enc) do |t|
|
63
|
+
enc = encoding || @encoding
|
64
|
+
temp = BFS::TempWriter.new(path, encoding: enc, perm: perm) do |t|
|
70
65
|
File.open(t, encoding: enc) do |file|
|
71
|
-
@bucket.create_file(file, path, opts)
|
66
|
+
@bucket.create_file(file, path, **opts)
|
72
67
|
end
|
73
68
|
end
|
74
69
|
return temp unless block
|
@@ -81,13 +76,13 @@ module BFS
|
|
81
76
|
end
|
82
77
|
|
83
78
|
# Opens an existing file for reading
|
84
|
-
def open(path, opts
|
79
|
+
def open(path, encoding: nil, tempdir: nil, **opts, &block)
|
85
80
|
path = full_path(path)
|
86
|
-
enc =
|
81
|
+
enc = encoding || @encoding
|
87
82
|
file = @bucket.file(path)
|
88
83
|
raise BFS::FileNotFound, trim_prefix(path) unless file
|
89
84
|
|
90
|
-
temp = Tempfile.new(File.basename(path), encoding: enc)
|
85
|
+
temp = Tempfile.new(File.basename(path), tempdir, encoding: enc)
|
91
86
|
temp.close
|
92
87
|
file.download temp.path, opts
|
93
88
|
|
@@ -95,19 +90,19 @@ module BFS
|
|
95
90
|
end
|
96
91
|
|
97
92
|
# Deletes a file.
|
98
|
-
def rm(path, opts
|
93
|
+
def rm(path, **opts)
|
99
94
|
path = full_path(path)
|
100
95
|
file = @bucket.file(path)
|
101
|
-
file&.delete(opts)
|
96
|
+
file&.delete(**opts)
|
102
97
|
end
|
103
98
|
|
104
99
|
# Copies a file.
|
105
|
-
def cp(src, dst, opts
|
100
|
+
def cp(src, dst, **opts)
|
106
101
|
src = full_path(src)
|
107
102
|
file = @bucket.file(src)
|
108
103
|
raise BFS::FileNotFound, trim_prefix(src) unless file
|
109
104
|
|
110
|
-
file.copy(full_path(dst), opts)
|
105
|
+
file.copy(full_path(dst), **opts)
|
111
106
|
end
|
112
107
|
end
|
113
108
|
end
|
@@ -119,10 +114,10 @@ BFS.register('gs') do |url|
|
|
119
114
|
prefix = nil if prefix.empty?
|
120
115
|
|
121
116
|
BFS::Bucket::GS.new url.host,
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
117
|
+
prefix: prefix,
|
118
|
+
project_id: params.key?('project_id') ? params['project_id'].first : nil,
|
119
|
+
credentials: params.key?('credentials') ? params['credentials'].first : nil,
|
120
|
+
acl: params.key?('acl') ? params['acl'].first : nil,
|
121
|
+
timeout: params.key?('timeout') ? params['timeout'].first.to_i : nil,
|
122
|
+
retries: params.key?('retries') ? params['retries'].first.to_i : nil
|
128
123
|
end
|
data/spec/bfs/bucket/gs_spec.rb
CHANGED
@@ -30,7 +30,7 @@ RSpec.describe BFS::Bucket::GS, if: run_spec do
|
|
30
30
|
it_behaves_like 'a bucket'
|
31
31
|
|
32
32
|
it 'should resolve from URL' do
|
33
|
-
bucket = BFS.resolve("gs://#{sandbox[:bucket]}/?
|
33
|
+
bucket = BFS.resolve("gs://#{sandbox[:bucket]}/?project_id=#{sandbox[:project]}")
|
34
34
|
expect(bucket).to be_instance_of(described_class)
|
35
35
|
expect(bucket.name).to eq(sandbox[:bucket])
|
36
36
|
expect(bucket.instance_variable_get(:@prefix)).to be_nil
|
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.6.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: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bfs
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.6.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.6.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: google-cloud-storage
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.
|
63
|
+
version: 2.5.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.
|
70
|
+
rubygems_version: 3.0.6
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: GS bucket adapter for bfs
|