bfs-gs 0.6.0 → 0.6.5
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 +1 -1
- data/lib/bfs/bucket/gs.rb +26 -39
- 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: 460902d2cc058b953f1180b5c6baa79979e13ce6601bf7e072a6c422d17ac348
|
4
|
+
data.tar.gz: 27aba18d5a723270b62575f9beb922a1614c835a03c909454f0dfbed47d4b1bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6b0f5d5881f56eabb64303264f3faf9b9b76f602ee90ca6f92e39987cdfbae2071c668690b024833afcd2ba10a6c79e15406c26f4ae4899865d6fb2290e6131
|
7
|
+
data.tar.gz: 30825d6a15e154fda4db8fa9eae5bd2ab7652e239660f3e56ca21d2745439c2a7c781e60a85880e9a5ab9e0ce9f7fa937c7e812c2a12cd21cfd661490b58b730
|
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
@@ -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
|
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
|
+
def initialize(name, prefix: nil, acl: nil, client: nil, **opts)
|
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)
|
@@ -39,13 +32,13 @@ module BFS
|
|
39
32
|
end
|
40
33
|
|
41
34
|
# Lists the contents of a bucket using a glob pattern
|
42
|
-
def ls(pattern='**/*', opts
|
35
|
+
def ls(pattern = '**/*', **opts)
|
43
36
|
prefix = pattern[%r{^[^\*\?\{\}\[\]]+/}]
|
44
37
|
prefix = File.join(*[@prefix, prefix].compact) if @prefix
|
45
38
|
opts = opts.merge(prefix: prefix) if prefix
|
46
39
|
|
47
40
|
Enumerator.new do |y|
|
48
|
-
@bucket.files(opts).all do |file|
|
41
|
+
@bucket.files(**opts).all do |file|
|
49
42
|
name = trim_prefix(file.name)
|
50
43
|
y << name if File.fnmatch?(pattern, name, File::FNM_PATHNAME)
|
51
44
|
end
|
@@ -53,23 +46,22 @@ module BFS
|
|
53
46
|
end
|
54
47
|
|
55
48
|
# Info returns the object info
|
56
|
-
def info(path, _opts
|
49
|
+
def info(path, **_opts)
|
57
50
|
path = full_path(path)
|
58
51
|
file = @bucket.file(path)
|
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
|
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
|
-
|
72
|
-
@bucket.create_file(file, path, opts)
|
62
|
+
temp = BFS::TempWriter.new(path, encoding: encoding, perm: perm) do |t|
|
63
|
+
File.open(t, encoding: encoding) do |file|
|
64
|
+
@bucket.create_file(file, path, **opts)
|
73
65
|
end
|
74
66
|
end
|
75
67
|
return temp unless block
|
@@ -82,48 +74,43 @@ module BFS
|
|
82
74
|
end
|
83
75
|
|
84
76
|
# Opens an existing file for reading
|
85
|
-
def open(path, opts
|
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.
|
99
|
-
def rm(path, opts
|
90
|
+
def rm(path, **opts)
|
100
91
|
path = full_path(path)
|
101
92
|
file = @bucket.file(path)
|
102
|
-
file&.delete(opts)
|
93
|
+
file&.delete(**opts)
|
103
94
|
end
|
104
95
|
|
105
96
|
# Copies a file.
|
106
|
-
def cp(src, dst, opts
|
97
|
+
def cp(src, dst, **opts)
|
107
98
|
src = full_path(src)
|
108
99
|
file = @bucket.file(src)
|
109
100
|
raise BFS::FileNotFound, trim_prefix(src) unless file
|
110
101
|
|
111
|
-
file.copy(full_path(dst), opts)
|
102
|
+
file.copy(full_path(dst), **opts)
|
112
103
|
end
|
113
104
|
end
|
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,
|
123
|
-
|
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
|
112
|
+
BFS::Bucket::GS.new url.host, **opts.slice(:project_id, :credentials, :acl),
|
113
|
+
prefix: prefix,
|
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.6.
|
4
|
+
version: 0.6.5
|
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-17 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.6.
|
19
|
+
version: 0.6.5
|
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.6.
|
26
|
+
version: 0.6.5
|
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.
|
70
|
+
rubygems_version: 3.1.2
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: GS bucket adapter for bfs
|