bfs 0.1.0 → 0.2.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/lib/bfs.rb +8 -0
- data/lib/bfs/blob.rb +50 -0
- data/lib/bfs/bucket.rb +4 -3
- data/lib/bfs/bucket/abstract.rb +1 -1
- data/lib/bfs/bucket/fs.rb +16 -0
- data/spec/bfs/blob_spec.rb +27 -0
- data/spec/bfs/bucket/fs_spec.rb +16 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a625c88ce474019b57f7ba1cd34618f79efa2b090ec8601934805e04a4ce6f41
|
4
|
+
data.tar.gz: 7f3a794d63f4c1490fcc3c5c509b6d10c749f987cbd364304b7b8b867f0725d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc5f7c5c9313736c23753a9bb9d7837bcd0586782b9014d1032771f17ad9c76e47bebaa8fd9b5a7a99c23610193602bf2775bdd275f3167e3c9f81d1993946b
|
7
|
+
data.tar.gz: 56a751d745a83226e99f646f7586ce6a54dc053ee6acb796735fe8afdeec869d88318963445a1315579ec3c37e272c0833fafd0a4b8ac8e4371e01ca155a4150
|
data/lib/bfs.rb
CHANGED
@@ -15,8 +15,16 @@ module BFS
|
|
15
15
|
|
16
16
|
rsl.call(url)
|
17
17
|
end
|
18
|
+
|
19
|
+
def self.norm_path(path)
|
20
|
+
path = path.to_s.dup
|
21
|
+
path.gsub!(File::SEPARATOR, '/')
|
22
|
+
path.sub!(%r{^/+}, '')
|
23
|
+
path
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
require 'bfs/helpers'
|
21
28
|
require 'bfs/bucket'
|
22
29
|
require 'bfs/errors'
|
30
|
+
require 'bfs/blob'
|
data/lib/bfs/blob.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module BFS
|
2
|
+
# Blobs are references to single blob objects within a bucket.
|
3
|
+
class Blob
|
4
|
+
attr_reader :path
|
5
|
+
|
6
|
+
def initialize(url)
|
7
|
+
url = URI.parse(url) unless url.is_a?(::URI)
|
8
|
+
@bucket = BFS.resolve(url)
|
9
|
+
@path = BFS.norm_path(url.path)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Info returns the blob info
|
13
|
+
def info(opts={})
|
14
|
+
@bucket.info(path, opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates the blob and opens it for writing
|
18
|
+
def create(opts={}, &block)
|
19
|
+
@bucket.create(path, opts, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Opens the blob for reading
|
23
|
+
# May raise BFS::FileNotFound
|
24
|
+
def open(opts={}, &block)
|
25
|
+
@bucket.open(path, opts, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Deletes the blob
|
29
|
+
def rm(opts={})
|
30
|
+
@bucket.rm(path, opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Shortcut method to read the contents of the blob
|
34
|
+
def read(opts={})
|
35
|
+
open(opts, &:read)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Shortcut method to write data to blob
|
39
|
+
def write(data, opts={})
|
40
|
+
create(opts) {|f| f.write data }
|
41
|
+
end
|
42
|
+
|
43
|
+
# Moves blob to dst
|
44
|
+
def mv(dst, opts={})
|
45
|
+
dst = BFS.norm_path(dst)
|
46
|
+
@bucket.mv(path, dst, opts)
|
47
|
+
@path = dst
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/bfs/bucket.rb
CHANGED
data/lib/bfs/bucket/abstract.rb
CHANGED
data/lib/bfs/bucket/fs.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'bfs'
|
2
|
+
require 'cgi'
|
2
3
|
require 'fileutils'
|
3
4
|
require 'pathname'
|
4
5
|
|
@@ -77,3 +78,18 @@ module BFS
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
81
|
+
|
82
|
+
BFS.register('file') do |url|
|
83
|
+
params = CGI.parse(url.query.to_s)
|
84
|
+
|
85
|
+
parts = [url.host, url.path].compact
|
86
|
+
root = case params.key?('scope') && params['scope'].first
|
87
|
+
when 'root'
|
88
|
+
'/'
|
89
|
+
when 'dir'
|
90
|
+
File.dirname(File.join(*parts))
|
91
|
+
else
|
92
|
+
File.join(*parts)
|
93
|
+
end
|
94
|
+
BFS::Bucket::FS.new root
|
95
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe BFS::Blob do
|
4
|
+
let(:bucket) { BFS::Bucket::InMem.new }
|
5
|
+
before { allow(BFS).to receive(:resolve).and_return(bucket) }
|
6
|
+
subject { described_class.new('memtest://bucket/path/to/file.txt') }
|
7
|
+
|
8
|
+
it 'should move' do
|
9
|
+
expect(subject.path).to eq('path/to/file.txt')
|
10
|
+
expect { subject.mv('/to/other/path.txt') }.to raise_error(BFS::FileNotFound)
|
11
|
+
|
12
|
+
subject.write('TESTDATA')
|
13
|
+
subject.mv('/to/other/path.txt')
|
14
|
+
expect(subject.path).to eq('to/other/path.txt')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should write/read' do
|
18
|
+
expect { subject.read }.to raise_error(BFS::FileNotFound)
|
19
|
+
subject.write('TESTDATA')
|
20
|
+
|
21
|
+
info = subject.info
|
22
|
+
expect(info).to eq(BFS::FileInfo.new('path/to/file.txt', 8, info.mtime))
|
23
|
+
expect(info.mtime).to be_within(1).of(Time.now)
|
24
|
+
|
25
|
+
expect(subject.read).to eq('TESTDATA')
|
26
|
+
end
|
27
|
+
end
|
data/spec/bfs/bucket/fs_spec.rb
CHANGED
@@ -6,4 +6,20 @@ RSpec.describe BFS::Bucket::FS do
|
|
6
6
|
subject { described_class.new(tmpdir) }
|
7
7
|
|
8
8
|
it_behaves_like 'a bucket'
|
9
|
+
|
10
|
+
it 'should resolve from URL' do
|
11
|
+
File.open(File.join(tmpdir, 'test.txt'), 'w') {|f| f.write 'TESTDATA' }
|
12
|
+
|
13
|
+
bucket = BFS.resolve("file://#{tmpdir}")
|
14
|
+
expect(bucket).to be_instance_of(described_class)
|
15
|
+
expect(bucket.ls).to eq(['test.txt'])
|
16
|
+
|
17
|
+
bucket = BFS.resolve("file://#{tmpdir}/test.txt?scope=dir")
|
18
|
+
expect(bucket).to be_instance_of(described_class)
|
19
|
+
expect(bucket.ls).to eq(['test.txt'])
|
20
|
+
|
21
|
+
bucket = BFS.resolve("file://#{tmpdir}/test.txt?scope=root")
|
22
|
+
expect(bucket).to be_instance_of(described_class)
|
23
|
+
expect(bucket.instance_variable_get(:@root).to_s).to eq('/')
|
24
|
+
end
|
9
25
|
end
|
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.
|
4
|
+
version: 0.2.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: 2018-10-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Minimalist abstraction for bucket storage
|
14
14
|
email: dimitrij@blacksquaremedia.com
|
@@ -18,12 +18,14 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- bfs.gemspec
|
20
20
|
- lib/bfs.rb
|
21
|
+
- lib/bfs/blob.rb
|
21
22
|
- lib/bfs/bucket.rb
|
22
23
|
- lib/bfs/bucket/abstract.rb
|
23
24
|
- lib/bfs/bucket/fs.rb
|
24
25
|
- lib/bfs/bucket/in_mem.rb
|
25
26
|
- lib/bfs/errors.rb
|
26
27
|
- lib/bfs/helpers.rb
|
28
|
+
- spec/bfs/blob_spec.rb
|
27
29
|
- spec/bfs/bucket/fs_spec.rb
|
28
30
|
- spec/bfs/bucket/in_mem_spec.rb
|
29
31
|
homepage: https://github.com/bsm/bfs.rb
|
@@ -46,10 +48,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
48
|
version: '0'
|
47
49
|
requirements: []
|
48
50
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.7.
|
51
|
+
rubygems_version: 2.7.7
|
50
52
|
signing_key:
|
51
53
|
specification_version: 4
|
52
54
|
summary: Multi-platform cloud bucket adapter
|
53
55
|
test_files:
|
56
|
+
- spec/bfs/blob_spec.rb
|
54
57
|
- spec/bfs/bucket/fs_spec.rb
|
55
58
|
- spec/bfs/bucket/in_mem_spec.rb
|