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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82a8cd1767f0f915a8345f5aa9ad79699b8a5a1d5f102cae9c77dd822d2a4e77
4
- data.tar.gz: 15c9601e95620ccc4904c94e6e813cac13ea3b46aa398797433d03d9c5ccf219
3
+ metadata.gz: 6ccb82fa9b3f6e02cf08f46538505c63160250cf81e85f15a277ea2fad06d87a
4
+ data.tar.gz: 198aa9725055cb44737406ed098dbcbec7c659d2e180a1d45b84e0a4dc5f30ee
5
5
  SHA512:
6
- metadata.gz: 92e9caded9b39f0194c79920b12a5d81ee3dbc0e21bace3ce8b7368ecea63ab9c7af739e02114f1cdff72337d09926ec3a7b8bbf5b2c60ebc65e88e7a17dd6da
7
- data.tar.gz: e492fc6856487d474b58d869844e51b240f629572d5d4118df20926ba2cbab5ec116e3af4ddfa7b7586a3ba82d03667d240adcc66f319c3b0106d7698ea81c7c
6
+ metadata.gz: a395f8bd4cf34bee034ba0a7c42d0021eddcf4f9e106fe3bc20efc37c55f0a5d6394a8ca50f47a6e2d1f20b1ba2ef20df263908bc7077afe1302a63d4d3422ed
7
+ data.tar.gz: 1a9c14cdef37a10ed2742da23ba483e0f3163b2d3c6f9011a37e6480acf0ab5e05daef4f6d629ee77fd40c7ac61a642ce34edea158378cf9e55fe43e19c46be9
@@ -13,5 +13,5 @@
13
13
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
14
14
  # License:: MIT
15
15
  class BazaRb
16
- VERSION = '0.9.0'
16
+ VERSION = '0.9.1'
17
17
  end
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
- slice = unzip(slice)
762
- msg << "unzipped to #{slice.bytesize} bytes"
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')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko