bfs-s3 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 770bbfff15bd69519f2349867f883a6c47c839de21547fc9d323d5809e76dfd0
4
- data.tar.gz: 47ee1a747cb2a821833bab758b06c38160b06bb11f4b9dc7b68d43bf706f53e3
3
+ metadata.gz: 4103371b6039d46aba27c96dc7ec740935ffa8353a1d52d09b1225ba6f2e152d
4
+ data.tar.gz: 179845d43b49fd2681230f3a3a064496983e5156382575e7c234aeda654bfc04
5
5
  SHA512:
6
- metadata.gz: c5c5037ec228f4945c4d530c14d3f4c62982088462ea91d84dc06c66eec9fa2de6d1e1ce19f8b4957fd7d1a8ba2c32b8df1aaadd1b170383d860857b06407499
7
- data.tar.gz: 8b5596aefdc9333fdb5f4b0f242cea295d2d7b80302c20fa2c971ababbce1d795325eb935c5f75633d9dfb4ec543a7bf4b32b689faa4d3140fa1c12bd7eb7ad2
6
+ metadata.gz: 54a4afbfaae7f55b40fdeeab4dba2990a133525e2d513c65c13036e15703d65394e0cc581141448cdaed79c9f5435bc4087d78d5f56963c69c70992059989445
7
+ data.tar.gz: 84d9af9c6f5abc03751d158e9716aaa58841ded7f182750c11c5f06744fca3931e1f7e8e7ae7715fb88ef735b03958369a792fe943eaf717237e78666df4d918
data/bfs-s3.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.required_ruby_version = '>= 2.2.0'
19
19
 
20
20
  s.add_dependency 'aws-sdk-s3'
21
- s.add_dependency 'bfs'
21
+ s.add_dependency 'bfs', s.version
22
22
  end
data/lib/bfs/bucket/s3.rb CHANGED
@@ -36,9 +36,17 @@ module BFS
36
36
 
37
37
  # Lists the contents of a bucket using a glob pattern
38
38
  def ls(pattern='**/*', opts={})
39
- @client.list_objects_v2(opts.merge(bucket: name)).contents.select do |obj|
40
- File.fnmatch?(pattern, obj.key, File::FNM_PATHNAME)
41
- end.map(&:key)
39
+ next_token = nil
40
+ Enumerator.new do |y|
41
+ loop do
42
+ resp = @client.list_objects_v2 opts.merge(bucket: name, continuation_token: next_token)
43
+ resp.contents.each do |obj|
44
+ y << obj.key if File.fnmatch?(pattern, obj.key, File::FNM_PATHNAME)
45
+ end
46
+ next_token = resp.next_continuation_token.to_s
47
+ break if next_token.empty?
48
+ end
49
+ end
42
50
  end
43
51
 
44
52
  # Info returns the object info
@@ -85,7 +93,7 @@ module BFS
85
93
  # Opens an existing file for reading
86
94
  def open(path, opts={}, &block)
87
95
  path = norm_path(path)
88
- temp = Tempfile.new(File.basename(path))
96
+ temp = Tempfile.new(File.basename(path), binmode: true)
89
97
  temp.close
90
98
 
91
99
  opts = opts.merge(
@@ -1,59 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe BFS::Bucket::S3 do
4
- let(:client) { double('Aws::S3::Client') }
5
- let(:files) { {} }
6
- subject { described_class.new('mock-bucket', client: client) }
4
+ let(:files) { {} }
5
+ let :mock_client do
6
+ client = double Aws::S3::Client
7
7
 
8
- # stub put_object calls and store file data
9
- before do
10
8
  allow(client).to receive(:put_object).with(hash_including(bucket: 'mock-bucket')) do |opts|
11
9
  files[opts[:key]] = opts[:body].read
12
10
  nil
13
11
  end
14
- end
15
12
 
16
- # stub get_object calls
17
- before do
18
13
  allow(client).to receive(:get_object).with(hash_including(bucket: 'mock-bucket')) do |opts|
19
14
  data = files[opts[:key]]
20
15
  raise Aws::S3::Errors::NoSuchKey.new(nil, nil) unless data
21
16
 
22
- File.open(opts[:response_target], 'w') {|f| f.write(data) }
17
+ File.open(opts[:response_target], 'wb') {|f| f.write(data) }
23
18
  nil
24
19
  end
25
- end
26
20
 
27
- before do
28
21
  allow(client).to receive(:delete_object).with(hash_including(bucket: 'mock-bucket')) do |opts|
29
22
  raise Aws::S3::Errors::NoSuchKey.new(nil, nil) unless files.key?(opts[:key])
30
23
 
31
24
  files.delete(opts[:key])
32
25
  nil
33
26
  end
34
- end
35
27
 
36
- # stub list_objects_v2 calls
37
- before do
38
- allow(client).to receive(:list_objects_v2).with(bucket: 'mock-bucket') do |*|
28
+ allow(client).to receive(:list_objects_v2).with(bucket: 'mock-bucket', continuation_token: nil) do |*|
39
29
  contents = files.keys.map {|key| Aws::S3::Types::Object.new(key: key) }
40
- double 'ListObjectsV2Response', contents: contents
30
+ double 'ListObjectsV2Response', contents: contents, next_continuation_token: ''
31
+ end
32
+ allow(client).to receive(:list_objects_v2).with(bucket: 'mock-bucket', max_keys: 1, prefix: 'a/b/c.txt') do |*|
33
+ obj = Aws::S3::Types::Object.new(key: 'a/b/c.txt', size: 10, last_modified: Time.now)
34
+ double 'ListObjectsV2Response', contents: [obj]
35
+ end
36
+ allow(client).to receive(:list_objects_v2).with(bucket: 'mock-bucket', max_keys: 1, prefix: 'missing.txt') do |*|
37
+ double 'ListObjectsV2Response', contents: []
41
38
  end
42
- end
43
-
44
- # stub list_objects_v2, single object calls
45
- before do
46
- match = double 'ListObjectsV2Response', contents: [
47
- Aws::S3::Types::Object.new(key: 'a/b/c.txt', size: 10, last_modified: Time.now),
48
- ]
49
- no_match = double 'ListObjectsV2Response', contents: []
50
-
51
- allow(client).to receive(:list_objects_v2).with(bucket: 'mock-bucket', max_keys: 1, prefix: 'a/b/c.txt').and_return(match)
52
- allow(client).to receive(:list_objects_v2).with(bucket: 'mock-bucket', max_keys: 1, prefix: 'missing.txt').and_return(no_match)
53
- end
54
39
 
55
- # stub copy_object calls
56
- before do
57
40
  allow(client).to receive(:copy_object).with(hash_including(bucket: 'mock-bucket')) do |opts|
58
41
  src = opts[:copy_source].sub('/mock-bucket/', '')
59
42
  raise Aws::S3::Errors::NoSuchKey.new(nil, nil) unless files.key?(src)
@@ -61,8 +44,11 @@ RSpec.describe BFS::Bucket::S3 do
61
44
  files[opts[:key]] = files[src]
62
45
  nil
63
46
  end
47
+
48
+ client
64
49
  end
65
50
 
51
+ subject { described_class.new('mock-bucket', client: mock_client) }
66
52
  it_behaves_like 'a bucket'
67
53
 
68
54
  it 'should resolve from URL' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfs-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.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-18 00:00:00.000000000 Z
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bfs
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.3.0
41
41
  description: https://github.com/bsm/bfs.rb
42
42
  email: dimitrij@blacksquaremedia.com
43
43
  executables: []