bfs 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bfs/bucket/abstract.rb +13 -0
- data/lib/bfs/bucket/fs.rb +18 -2
- data/lib/bfs/bucket/in_mem.rb +9 -1
- data/lib/bfs/helpers.rb +4 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f63579ab84fab2e5ebe18ad08e9565c4510fbaf812a7bc71316df2b4cc9c6c3a
|
4
|
+
data.tar.gz: ee8adb7378ca2fddb0b476fd0ca3ea85429d5ab0afde19593b6557a0dae418b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 974f6428f3dbfefa68aa9fa2497e4763ee6418fed59afe5408cee7e7166a26952d25fb754737af318c28a8ebd755a50786c04d589742cb073105139fddf4d787
|
7
|
+
data.tar.gz: edc36b9aab8e1aabf9846235e50546d01aac0efd5477234bd0bff5ab39b67c85e527972beaba42cfdba545b854cae531c4e02703d298113339facc368e3b605f
|
data/lib/bfs/bucket/abstract.rb
CHANGED
@@ -30,16 +30,26 @@ module BFS
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# Shortcut method to read the contents of a file into memory
|
33
|
+
#
|
34
|
+
# @param [String] path The path to read from.
|
35
|
+
# @param [Hash] opts Additional options, see #open.
|
33
36
|
def read(path, opts={})
|
34
37
|
open(path, opts, &:read)
|
35
38
|
end
|
36
39
|
|
37
40
|
# Shortcut method to write data to path
|
41
|
+
#
|
42
|
+
# @param [String] path The path to write to.
|
43
|
+
# @param [String] data The data to write.
|
44
|
+
# @param [Hash] opts Additional options, see #create.
|
38
45
|
def write(path, data, opts={})
|
39
46
|
create(path, opts) {|f| f.write data }
|
40
47
|
end
|
41
48
|
|
42
49
|
# Copies src to dst
|
50
|
+
#
|
51
|
+
# @param [String] src The source path.
|
52
|
+
# @param [String] dst The destination path.
|
43
53
|
def cp(src, dst, opts={})
|
44
54
|
open(src, opts) do |r|
|
45
55
|
create(dst, opts) do |w|
|
@@ -49,6 +59,9 @@ module BFS
|
|
49
59
|
end
|
50
60
|
|
51
61
|
# Moves src to dst
|
62
|
+
#
|
63
|
+
# @param [String] src The source path.
|
64
|
+
# @param [String] dst The destination path.
|
52
65
|
def mv(src, dst, _opts={})
|
53
66
|
cp(src, dst)
|
54
67
|
rm(src)
|
data/lib/bfs/bucket/fs.rb
CHANGED
@@ -30,11 +30,15 @@ module BFS
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# Creates a new file and opens it for writing
|
33
|
-
|
33
|
+
#
|
34
|
+
# @param [String] path The creation path.
|
35
|
+
# @param [Hash] opts Additional options.
|
36
|
+
# @option opts [String] :encoding Custom encoding.
|
37
|
+
def create(path, opts={}, &block)
|
34
38
|
full = @root.join(norm_path(path))
|
35
39
|
FileUtils.mkdir_p(full.dirname.to_s)
|
36
40
|
|
37
|
-
temp = BFS::TempWriter.new(full) {|t| FileUtils.mv t, full.to_s }
|
41
|
+
temp = BFS::TempWriter.new(full, opts) {|t| FileUtils.mv t, full.to_s }
|
38
42
|
return temp unless block
|
39
43
|
|
40
44
|
begin
|
@@ -45,6 +49,10 @@ module BFS
|
|
45
49
|
end
|
46
50
|
|
47
51
|
# Opens an existing file for reading
|
52
|
+
#
|
53
|
+
# @param [String] path The path to open.
|
54
|
+
# @param [Hash] opts Additional options.
|
55
|
+
# @option opts [String] :encoding Custom encoding.
|
48
56
|
def open(path, opts={}, &block)
|
49
57
|
path = norm_path(path)
|
50
58
|
full = @root.join(path)
|
@@ -54,12 +62,17 @@ module BFS
|
|
54
62
|
end
|
55
63
|
|
56
64
|
# Deletes a file.
|
65
|
+
#
|
66
|
+
# @param [String] path The path to delete.
|
57
67
|
def rm(path, _opts={})
|
58
68
|
full = @root.join(norm_path(path))
|
59
69
|
FileUtils.rm_f full.to_s
|
60
70
|
end
|
61
71
|
|
62
72
|
# Copies a file.
|
73
|
+
#
|
74
|
+
# @param [String] src The source path.
|
75
|
+
# @param [String] dst The destination path.
|
63
76
|
def cp(src, dst, _opts={})
|
64
77
|
full_src = @root.join(norm_path(src))
|
65
78
|
full_dst = @root.join(norm_path(dst))
|
@@ -70,6 +83,9 @@ module BFS
|
|
70
83
|
end
|
71
84
|
|
72
85
|
# Moves a file.
|
86
|
+
#
|
87
|
+
# @param [String] src The source path.
|
88
|
+
# @param [String] dst The destination path.
|
73
89
|
def mv(src, dst, _opts={})
|
74
90
|
full_src = @root.join(norm_path(src))
|
75
91
|
full_dst = @root.join(norm_path(dst))
|
data/lib/bfs/bucket/in_mem.rb
CHANGED
@@ -34,9 +34,17 @@ module BFS
|
|
34
34
|
BFS::FileInfo.new(path, entry.io.size, entry.mtime, entry.content_type, entry.metadata)
|
35
35
|
end
|
36
36
|
|
37
|
-
# Creates a new file and opens it for writing
|
37
|
+
# Creates a new file and opens it for writing.
|
38
|
+
#
|
39
|
+
# @param [String] path The creation path.
|
40
|
+
# @param [Hash] opts Additional options.
|
41
|
+
# @option opts [String] :encoding Custom encoding.
|
42
|
+
# @option opts [String] :content_type Custom content type.
|
43
|
+
# @option opts [Hash] :metadata Metadata key-value pairs.
|
38
44
|
def create(path, opts={}, &block)
|
39
45
|
io = StringIO.new
|
46
|
+
opts[:encoding] ? io.set_encoding(opts[:encoding]) : io.binmode
|
47
|
+
|
40
48
|
@files[norm_path(path)] = Entry.new(io, Time.now, opts[:content_type], opts[:metadata] || {})
|
41
49
|
return io unless block
|
42
50
|
|
data/lib/bfs/helpers.rb
CHANGED
@@ -2,9 +2,11 @@ require 'tempfile'
|
|
2
2
|
|
3
3
|
module BFS
|
4
4
|
class TempWriter
|
5
|
-
def initialize(name, &closer)
|
5
|
+
def initialize(name, opts={}, &closer)
|
6
|
+
opts = opts.merge(binmode: true) unless opts[:encoding]
|
7
|
+
|
6
8
|
@closer = closer
|
7
|
-
@tempfile = ::Tempfile.new(File.basename(name.to_s),
|
9
|
+
@tempfile = ::Tempfile.new(File.basename(name.to_s), opts)
|
8
10
|
end
|
9
11
|
|
10
12
|
def path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
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-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Minimalist abstraction for bucket storage
|
14
14
|
email: dimitrij@blacksquaremedia.com
|
@@ -47,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
requirements: []
|
50
|
-
|
51
|
-
rubygems_version: 2.7.7
|
50
|
+
rubygems_version: 3.0.2
|
52
51
|
signing_key:
|
53
52
|
specification_version: 4
|
54
53
|
summary: Multi-platform cloud bucket adapter
|