baza.rb 0.9.2 → 0.9.3
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 +2 -4
- data/test/test_baza-rb.rb +17 -12
- 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: 1dc6218bb18b7baff1acf3119b775c05a7fc1200d8fe6bea72de26e052be2028
|
4
|
+
data.tar.gz: 4b58db5eda95b13edea4b09a223a3d787a4cbeffc80eb0025b8a16f2ed587fd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a444b7f90eb26e3517e40d01ddcb1654b1ed7e027c397e0892ee01d5be286872910c7124317a187f55ecb9ac6d437d0d7055496cedb52a0a69c59158b3ba447d
|
7
|
+
data.tar.gz: cc40e75452008681775d7428861f161058f1fa6b3127e0d80c84e1a29296e75bb76a3554920614fa42d5393a2bb67d37fb3906376ed63c121f1135f7233d5c46
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -732,9 +732,9 @@ class BazaRb
|
|
732
732
|
def download(uri, file)
|
733
733
|
FileUtils.mkdir_p(File.dirname(file))
|
734
734
|
FileUtils.rm_f(file)
|
735
|
+
FileUtils.touch(file)
|
735
736
|
chunk = 0
|
736
737
|
elapsed(@loog) do
|
737
|
-
pos = 0
|
738
738
|
loop do
|
739
739
|
request = Typhoeus::Request.new(
|
740
740
|
uri.to_s,
|
@@ -742,7 +742,7 @@ class BazaRb
|
|
742
742
|
headers: headers.merge(
|
743
743
|
'Accept' => '*',
|
744
744
|
'Accept-Encoding' => 'gzip',
|
745
|
-
'Range' => "bytes=#{
|
745
|
+
'Range' => "bytes=#{File.size(file)}-"
|
746
746
|
),
|
747
747
|
connecttimeout: @timeout,
|
748
748
|
timeout: @timeout
|
@@ -782,8 +782,6 @@ class BazaRb
|
|
782
782
|
_b, e = range.split('-')
|
783
783
|
raise "Range is not valid (#{range.inspect})" unless e.match?(/^[0-9]+$/)
|
784
784
|
len = ret.headers['Content-Length'].to_i
|
785
|
-
pos = e.to_i
|
786
|
-
pos += 1 unless len.zero?
|
787
785
|
break if e.to_i == total.to_i - 1
|
788
786
|
chunk += 1
|
789
787
|
sleep(1) if len.zero?
|
data/test/test_baza-rb.rb
CHANGED
@@ -459,7 +459,7 @@ class TestBazaRb < Minitest::Test
|
|
459
459
|
WebMock.disable_net_connect!
|
460
460
|
Dir.mktmpdir do |dir|
|
461
461
|
file = File.join(dir, 'test.txt')
|
462
|
-
File.write(file,
|
462
|
+
File.write(file, "\x00\x00 hi, dude! \x00\xFF\xFE\x12")
|
463
463
|
stub_request(:put, 'https://example.org:443/durables/42')
|
464
464
|
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
465
465
|
.to_return(status: 200)
|
@@ -471,11 +471,12 @@ class TestBazaRb < Minitest::Test
|
|
471
471
|
WebMock.disable_net_connect!
|
472
472
|
Dir.mktmpdir do |dir|
|
473
473
|
file = File.join(dir, 'loaded.txt')
|
474
|
+
data = "\x00\xE0 привет \x00\x00\xFF\xFE\x12"
|
474
475
|
stub_request(:get, 'https://example.org:443/durables/42')
|
475
476
|
.with(headers: { 'X-Zerocracy-Token' => '000' })
|
476
|
-
.to_return(status: 200, body:
|
477
|
+
.to_return(status: 200, body: data, headers: {})
|
477
478
|
fake_baza.durable_load(42, file)
|
478
|
-
assert_equal(
|
479
|
+
assert_equal(data, File.read(file))
|
479
480
|
end
|
480
481
|
end
|
481
482
|
|
@@ -483,13 +484,17 @@ class TestBazaRb < Minitest::Test
|
|
483
484
|
WebMock.disable_net_connect!
|
484
485
|
Dir.mktmpdir do |dir|
|
485
486
|
file = File.join(dir, 'loaded.txt')
|
486
|
-
stub_request(:get, 'https://example.org:443/durables/42')
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
487
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
488
|
+
.with(headers: { 'Range' => 'bytes=0-' })
|
489
|
+
.to_return(status: 206, body: '', headers: { 'Content-Range' => 'bytes 0-0/*' })
|
490
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
491
|
+
.with(headers: { 'Range' => 'bytes=0-' })
|
492
|
+
.to_return(status: 206, body: 'привет', headers: { 'Content-Range' => 'bytes 0-11/25' })
|
493
|
+
stub_request(:get, 'https://example.org:443/durables/42')
|
494
|
+
.with(headers: { 'Range' => 'bytes=12-' })
|
495
|
+
.to_return(status: 206, body: " друг \xFF\xFE\x12", headers: { 'Content-Range' => 'bytes 12-24/25' })
|
491
496
|
fake_baza.durable_load(42, file)
|
492
|
-
assert_equal(
|
497
|
+
assert_equal("привет друг \xFF\xFE\x12", File.read(file))
|
493
498
|
end
|
494
499
|
end
|
495
500
|
|
@@ -681,7 +686,7 @@ class TestBazaRb < Minitest::Test
|
|
681
686
|
with_sinatra_server do |baza|
|
682
687
|
file = File.join(dir, 'x.txt')
|
683
688
|
baza.durable_load(42, file)
|
684
|
-
assert_equal(
|
689
|
+
assert_equal("Hello, \xFF\xFE\x12!", File.read(file))
|
685
690
|
end
|
686
691
|
end
|
687
692
|
end
|
@@ -701,13 +706,13 @@ class TestBazaRb < Minitest::Test
|
|
701
706
|
'I am alive'
|
702
707
|
end
|
703
708
|
get '/durables/42' do
|
704
|
-
|
709
|
+
\"Hello, \\xFF\\xFE\\x12!\"
|
705
710
|
end
|
706
711
|
"
|
707
712
|
)
|
708
713
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
709
714
|
host = '127.0.0.1'
|
710
|
-
qbash("bundle exec ruby #{Shellwords.escape(app)} -p #{port}", log: Loog::
|
715
|
+
qbash("bundle exec ruby #{Shellwords.escape(app)} -p #{port}", log: Loog::NULL, accept: nil) do
|
711
716
|
loop do
|
712
717
|
break if Typhoeus::Request.get("http://#{host}:#{port}").code == 200
|
713
718
|
sleep(0.1)
|