baza.rb 0.9.0 → 0.9.1
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/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +13 -3
- data/test/test_baza-rb.rb +25 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ccb82fa9b3f6e02cf08f46538505c63160250cf81e85f15a277ea2fad06d87a
|
4
|
+
data.tar.gz: 198aa9725055cb44737406ed098dbcbec7c659d2e180a1d45b84e0a4dc5f30ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a395f8bd4cf34bee034ba0a7c42d0021eddcf4f9e106fe3bc20efc37c55f0a5d6394a8ca50f47a6e2d1f20b1ba2ef20df263908bc7077afe1302a63d4d3422ed
|
7
|
+
data.tar.gz: 1a9c14cdef37a10ed2742da23ba483e0f3163b2d3c6f9011a37e6480acf0ab5e05daef4f6d629ee77fd40c7ac61a642ce34edea158378cf9e55fe43e19c46be9
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -40,6 +40,9 @@ class BazaRb
|
|
40
40
|
# Unexpected response arrived from the server.
|
41
41
|
class BadResponse < StandardError; end
|
42
42
|
|
43
|
+
# When server sent incorrectly compressed data.
|
44
|
+
class BadCompression < StandardError; end
|
45
|
+
|
43
46
|
# Initialize a new Zerocracy API client.
|
44
47
|
#
|
45
48
|
# @param [String] host The API host name (e.g., 'api.zerocracy.com')
|
@@ -587,6 +590,8 @@ class BazaRb
|
|
587
590
|
io = StringIO.new(data)
|
588
591
|
gz = Zlib::GzipReader.new(io)
|
589
592
|
gz.read
|
593
|
+
rescue Zlib::GzipFile::Error => e
|
594
|
+
raise BadCompression, "Failed to unzip #{data.bytesize} bytes: #{e.message}"
|
590
595
|
end
|
591
596
|
|
592
597
|
# Compress request parameters with gzip.
|
@@ -756,12 +761,17 @@ class BazaRb
|
|
756
761
|
('in gzip' if ret.headers['Content-Encoding'] == 'gzip'),
|
757
762
|
("ranged as #{ret.headers['Content-Range'].inspect}" if ret.headers['Content-Range'])
|
758
763
|
]
|
759
|
-
checked(ret, [200, 206])
|
764
|
+
ret = checked(ret, [200, 206])
|
760
765
|
if ret.headers['Content-Encoding'] == 'gzip'
|
761
|
-
|
762
|
-
|
766
|
+
begin
|
767
|
+
slice = unzip(slice)
|
768
|
+
msg << "unzipped to #{slice.bytesize} bytes"
|
769
|
+
rescue BazaRb::BadCompression => e
|
770
|
+
raise BazaRb::BadCompression, "#{msg.compact.join(', ')} (#{e.message})"
|
771
|
+
end
|
763
772
|
end
|
764
773
|
File.open(file, 'ab') do |f|
|
774
|
+
msg << "added to existed #{File.size(file)} bytes"
|
765
775
|
f.write(slice)
|
766
776
|
end
|
767
777
|
@loog.debug(msg.compact.join(', '))
|
data/test/test_baza-rb.rb
CHANGED
@@ -478,6 +478,31 @@ class TestBazaRb < Minitest::Test
|
|
478
478
|
end
|
479
479
|
end
|
480
480
|
|
481
|
+
def test_durable_load_in_chunks
|
482
|
+
WebMock.disable_net_connect!
|
483
|
+
Dir.mktmpdir do |dir|
|
484
|
+
file = File.join(dir, 'loaded.txt')
|
485
|
+
stub_request(:get, 'https://example.org:443/durables/42').to_return(
|
486
|
+
{ status: 206, body: '', headers: { 'Content-Range' => 'bytes 0-0/*', 'Content-Length' => '0' } },
|
487
|
+
{ status: 206, body: 'привет', headers: { 'Content-Range' => 'bytes 0-5/11', 'Content-Length' => '5' } },
|
488
|
+
{ status: 206, body: ' друг', headers: { 'Content-Range' => 'bytes 6-10/11', 'Content-Length' => '5' } }
|
489
|
+
)
|
490
|
+
fake_baza.durable_load(42, file)
|
491
|
+
assert_equal('привет друг', File.read(file))
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
def test_durable_load_with_broken_compression
|
496
|
+
WebMock.disable_net_connect!
|
497
|
+
Dir.mktmpdir do |dir|
|
498
|
+
file = File.join(dir, 'loaded.txt')
|
499
|
+
stub_request(:get, 'https://example.org:443/durables/42').to_return(
|
500
|
+
status: 200, body: 'this is not gzip!', headers: { 'Content-Encoding' => 'gzip' }
|
501
|
+
)
|
502
|
+
assert_raises(BazaRb::BadCompression) { fake_baza.durable_load(42, file) }
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
481
506
|
def test_durable_lock
|
482
507
|
WebMock.disable_net_connect!
|
483
508
|
stub_request(:get, 'https://example.org/csrf').to_return(body: 'token')
|