files.com 1.0.177 → 1.0.178

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: 6236a38036cb59b5c102a43cfff3b17a952724d11adb7e7cb40e4c6094625b12
4
- data.tar.gz: 05bffaed64301d1a786b5d95ddb4c4b998069845667229e8fc58c8f24d897301
3
+ metadata.gz: 8314f06e051c0563d980fca94b325614b675d6c406ddc7e286ebf132251cbd0c
4
+ data.tar.gz: e7e4cce1b266a01b4afacfdca4bbca65ab6c46e87e3be7cf6b9b828db31082bc
5
5
  SHA512:
6
- metadata.gz: 7c53856d76605d84b64a35641cd130fdc490cc01376e753fc196f735029ca030120b41b4205925d21504a4f46f539142c4fcc3eefc3ce49bcb5ad87196e15f53
7
- data.tar.gz: 2393d1836cdaf127d1b6bd05897718fc96ef9247a0f29af0ab5aa771747dfc571e3753c9a6e82f6a12cdaddf857b39e6c66f4de32c91d70d5be263955da89fae
6
+ metadata.gz: dde72ce18d054f8bd8c2ee9f0d2c0f0b99e5207663081c1d57b279640282ae42f07a2b77c88a5f42bef9198f24b61840deffe87edd77251fd97fba0c3a11bd5d
7
+ data.tar.gz: ee65038bc42cd105e3d89646d187b079be61244f049a63f5a363c0bf1ac165ed52492d16ce2c175a096e2bcdd71278d4789400d991802c78d9a35fefa24f7687
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.177
1
+ 1.0.178
@@ -154,7 +154,12 @@ module Files
154
154
  http.request request do |response|
155
155
  io.fulfill_content_length(response.content_length) if io.respond_to?(:fulfill_content_length)
156
156
  response.read_body do |chunk|
157
+ response.error! if response.code.to_i >= 300
158
+ io.ready! if io.respond_to?(:ready!)
157
159
  io << chunk
160
+ rescue => e
161
+ io.set_error(e) if io.respond_to?(:set_error)
162
+ io.close
158
163
  end
159
164
  end
160
165
  end
@@ -396,7 +396,7 @@ module Files
396
396
  ensure
397
397
  w.close
398
398
  end
399
- r
399
+ r.wait!(5)
400
400
  end
401
401
  end
402
402
 
@@ -18,13 +18,18 @@ module Files
18
18
  end
19
19
 
20
20
  def close
21
+ raise @with_error if @with_error
21
22
  super
22
23
  read_io.content_length_promise.try_set(nil)
23
24
  end
24
25
 
26
+ def set_error(e)
27
+ read_io.with_error = e
28
+ end
29
+
25
30
  protected
26
31
 
27
- attr_accessor :content_length
32
+ attr_accessor :content_length, :with_error
28
33
 
29
34
  def content_length_promise
30
35
  @content_length_promise ||= Concurrent::Promise.new { content_length }
@@ -1,8 +1,8 @@
1
1
  require "spec_helper"
2
2
  require "tempfile"
3
3
 
4
- RSpec.describe Files::File, :with_test_folder do
5
- xdescribe "#read" do
4
+ RSpec.describe Files::File, :with_test_folder, skip: ENV["GITLAB"] do
5
+ describe "#read" do
6
6
  before do
7
7
  Files::File.open(test_folder.join("[[strange stuff]]#yes.text").to_s, 'w', options) do |f|
8
8
  f.write("contents")
@@ -13,9 +13,19 @@ RSpec.describe Files::File, :with_test_folder do
13
13
  file = Files::File.find(test_folder.join("[[strange stuff]]#yes.text").to_s, {}, options)
14
14
  expect(file.read).to eq("contents")
15
15
  end
16
+
17
+ context "stream failure" do
18
+ let(:expired_download) { "https://s3.amazonaws.com/objects.brickftp.com/metadata/37868/52f55a21-1685-46aa-aaff-99ca8b172c00?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIEWLY3MN4YGZQOWA%2F20210621%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210621T202802Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&response-cache-control=no-cache%2C%20no-store&response-content-disposition=attachment%3B%20filename%3D%22write-as-io.txt%22&response-content-type=text%2Fplain&X-Amz-Signature=83d5b5789cbd2282bfea6e560e4319385135204dc0df3217930f96905c9cb18f" }
19
+
20
+ it "waits for io to be ready" do
21
+ file = Files::File.new
22
+ allow(file).to receive(:download_uri_with_load).and_return(expired_download)
23
+ expect { file.read_io }.to raise_error('403 "Forbidden"')
24
+ end
25
+ end
16
26
  end
17
27
 
18
- xdescribe "#read_io" do
28
+ describe "#read_io" do
19
29
  before do
20
30
  Files::File.open(test_folder.join("read.txt").to_s, 'w', options) do |f|
21
31
  f.write("contents")
@@ -28,9 +38,17 @@ RSpec.describe Files::File, :with_test_folder do
28
38
  expect(file.read_io.read).to eq("contents")
29
39
  expect(file.read_io.size).to eq("contents".length)
30
40
  end
41
+
42
+ it "works for file with zero bytes" do
43
+ file = Files::File.open("zero-byte.txt", 'w', options)
44
+ file.write("")
45
+ file.close
46
+ file = Files::File.find("zero-byte.txt", {}, options)
47
+ expect(file.read_io.read).to eq("")
48
+ end
31
49
  end
32
50
 
33
- xdescribe "#write" do
51
+ describe "#write" do
34
52
  it "can take string" do
35
53
  Files::File.open(test_folder.join("write-as-string.txt").to_s, 'w', options) do |f|
36
54
  f.write("I am a string")
@@ -65,4 +83,18 @@ RSpec.describe Files::File, :with_test_folder do
65
83
  temp_file.close
66
84
  end
67
85
  end
86
+
87
+ describe "#download_content" do
88
+ let(:file) {
89
+ Files::File.open(test_folder.join("write-as-string.txt").to_s, 'w', options) do |f|
90
+ f.write("I am a string")
91
+ end
92
+ }
93
+
94
+ it "can take arbitrary IO" do
95
+ file.download_content(io = StringIO.new)
96
+
97
+ expect(io.tap(&:rewind).read).to eq("I am a string")
98
+ end
99
+ end
68
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: files.com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.177
4
+ version: 1.0.178
5
5
  platform: ruby
6
6
  authors:
7
7
  - files.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-16 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable