bfs-gs 0.6.1 → 0.7.0
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 +16 -29
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2d89afa0f45efa9b6fd19cc525754cc52dd0860df44c1ca042371df28c1f75a
|
4
|
+
data.tar.gz: b5ec4ef496facbc6f062c81017ed0ed35f0a06f7e512b5a657688130bed041a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c7c2c221cb15b740721a1224a73ffb1203fefd0431253f8b07e12cec454aa8d1b8806381bbe5036ee607fdc582f43ab98a862471ac3c37e76dcb7cad79ab9c1
|
7
|
+
data.tar.gz: a8f78a4813033d7ebe7cb244ae68a3424aadbf251d845f909614325e35931bf85816a4e3aceffdf51e8520e9023aa0fbb1528a46a18801f9335b71ae16864de0
|
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.6.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
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'bfs'
|
2
2
|
require 'google/cloud/storage'
|
3
|
-
require 'cgi'
|
4
3
|
|
5
4
|
module BFS
|
6
5
|
module Bucket
|
@@ -21,17 +20,11 @@ module BFS
|
|
21
20
|
# @option opts [String] :acl set the default ACL.
|
22
21
|
# @option opts [Google::Cloud::Storage] :client custom client.
|
23
22
|
# @option opts [String] :encoding Custom encoding.
|
24
|
-
def initialize(name, **opts)
|
25
|
-
opts = opts.dup
|
26
|
-
opts.keys.each do |key|
|
27
|
-
val = opts.delete(key)
|
28
|
-
opts[key.to_sym] = val unless val.nil?
|
29
|
-
end
|
23
|
+
def initialize(name, prefix: nil, acl: nil, client: nil, **opts)
|
30
24
|
super(**opts)
|
31
25
|
|
32
|
-
@prefix =
|
33
|
-
|
34
|
-
client = opts.delete(:client) || Google::Cloud::Storage.new(**opts)
|
26
|
+
@prefix = prefix
|
27
|
+
client ||= Google::Cloud::Storage.new(**opts)
|
35
28
|
|
36
29
|
@name = name.to_s
|
37
30
|
@bucket = client.bucket(@name)
|
@@ -59,16 +52,15 @@ module BFS
|
|
59
52
|
raise BFS::FileNotFound, trim_prefix(path) unless file
|
60
53
|
|
61
54
|
name = trim_prefix(file.name)
|
62
|
-
BFS::FileInfo.new(name, file.size, file.updated_at.to_time, file.content_type, norm_meta(file.metadata))
|
55
|
+
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
56
|
end
|
64
57
|
|
65
58
|
# Creates a new file and opens it for writing
|
66
|
-
def create(path, **opts, &block)
|
59
|
+
def create(path, encoding: self.encoding, perm: self.perm, **opts, &block)
|
67
60
|
opts[:metadata] = norm_meta(opts[:metadata])
|
68
61
|
path = full_path(path)
|
69
|
-
|
70
|
-
|
71
|
-
File.open(t, encoding: enc) do |file|
|
62
|
+
temp = BFS::TempWriter.new(path, encoding: encoding, perm: perm) do |t|
|
63
|
+
File.open(t, encoding: encoding) do |file|
|
72
64
|
@bucket.create_file(file, path, **opts)
|
73
65
|
end
|
74
66
|
end
|
@@ -82,17 +74,16 @@ module BFS
|
|
82
74
|
end
|
83
75
|
|
84
76
|
# Opens an existing file for reading
|
85
|
-
def open(path, **opts, &block)
|
77
|
+
def open(path, encoding: self.encoding, tempdir: nil, **opts, &block)
|
86
78
|
path = full_path(path)
|
87
|
-
enc = opts.delete(:encoding) || @encoding
|
88
79
|
file = @bucket.file(path)
|
89
80
|
raise BFS::FileNotFound, trim_prefix(path) unless file
|
90
81
|
|
91
|
-
temp = Tempfile.new(File.basename(path), encoding:
|
82
|
+
temp = Tempfile.new(File.basename(path), tempdir, encoding: encoding)
|
92
83
|
temp.close
|
93
|
-
file.download
|
84
|
+
file.download(temp.path, **opts)
|
94
85
|
|
95
|
-
File.open(temp.path, encoding:
|
86
|
+
File.open(temp.path, encoding: encoding, &block)
|
96
87
|
end
|
97
88
|
|
98
89
|
# Deletes a file.
|
@@ -114,16 +105,12 @@ module BFS
|
|
114
105
|
end
|
115
106
|
end
|
116
107
|
|
117
|
-
BFS.register('gs') do |url|
|
118
|
-
|
119
|
-
prefix = BFS.norm_path(params.key?('prefix') ? params['prefix'].first : url.path)
|
108
|
+
BFS.register('gs') do |url, opts|
|
109
|
+
prefix = BFS.norm_path(opts.key?(:prefix) ? opts[:prefix] : url.path)
|
120
110
|
prefix = nil if prefix.empty?
|
121
111
|
|
122
|
-
BFS::Bucket::GS.new url.host,
|
112
|
+
BFS::Bucket::GS.new url.host, **opts.slice(:project_id, :credentials, :acl),
|
123
113
|
prefix: prefix,
|
124
|
-
|
125
|
-
|
126
|
-
acl: params.key?('acl') ? params['acl'].first : nil,
|
127
|
-
timeout: params.key?('timeout') ? params['timeout'].first.to_i : nil,
|
128
|
-
retries: params.key?('retries') ? params['retries'].first.to_i : nil
|
114
|
+
timeout: opts.key?(:timeout) ? opts[:timeout].to_i : nil,
|
115
|
+
retries: opts.key?(:retries) ? opts[:retries].to_i : nil
|
129
116
|
end
|
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.7.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: 2020-
|
11
|
+
date: 2020-05-28 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.7.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.
|
26
|
+
version: 0.7.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: google-cloud-storage
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 2.
|
63
|
+
version: 2.6.0
|
64
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|