|
17 | 17 | end
|
18 | 18 | end
|
19 | 19 |
|
| 20 | + describe 'decompress_with_pos' do |
| 21 | + it 'should return decompressed data and consumed input position' do |
| 22 | + str = "hello world test data" |
| 23 | + cstr = Zstd.compress(str) |
| 24 | + stream = Zstd::StreamingDecompress.new |
| 25 | + |
| 26 | + # Test with partial input |
| 27 | + result_array = stream.decompress_with_pos(cstr[0, 10]) |
| 28 | + expect(result_array).to be_an(Array) |
| 29 | + expect(result_array.length).to eq(2) |
| 30 | + |
| 31 | + decompressed_data = result_array[0] |
| 32 | + consumed_bytes = result_array[1] |
| 33 | + |
| 34 | + expect(decompressed_data).to be_a(String) |
| 35 | + expect(consumed_bytes).to be_a(Integer) |
| 36 | + expect(consumed_bytes).to be > 0 |
| 37 | + expect(consumed_bytes).to be <= 10 |
| 38 | + end |
| 39 | + |
| 40 | + it 'should work with complete compressed data' do |
| 41 | + str = "foo bar buzz" |
| 42 | + cstr = Zstd.compress(str) |
| 43 | + stream = Zstd::StreamingDecompress.new |
| 44 | + |
| 45 | + result_array = stream.decompress_with_pos(cstr) |
| 46 | + decompressed_data = result_array[0] |
| 47 | + consumed_bytes = result_array[1] |
| 48 | + |
| 49 | + expect(decompressed_data).to eq(str) |
| 50 | + expect(consumed_bytes).to eq(cstr.length) |
| 51 | + end |
| 52 | + |
| 53 | + it 'should work with multiple calls' do |
| 54 | + str = "test data for multiple calls" |
| 55 | + cstr = Zstd.compress(str) |
| 56 | + stream = Zstd::StreamingDecompress.new |
| 57 | + |
| 58 | + result = '' |
| 59 | + total_consumed = 0 |
| 60 | + chunk_size = 5 |
| 61 | + |
| 62 | + while total_consumed < cstr.length |
| 63 | + remaining_data = cstr[total_consumed..-1] |
| 64 | + chunk = remaining_data[0, chunk_size] |
| 65 | + |
| 66 | + result_array = stream.decompress_with_pos(chunk) |
| 67 | + decompressed_chunk = result_array[0] |
| 68 | + consumed_bytes = result_array[1] |
| 69 | + |
| 70 | + result << decompressed_chunk |
| 71 | + total_consumed += consumed_bytes |
| 72 | + |
| 73 | + expect(consumed_bytes).to be > 0 |
| 74 | + expect(consumed_bytes).to be <= chunk.length |
| 75 | + |
| 76 | + # If we consumed less than the chunk size, we might be done or need more data |
| 77 | + break if consumed_bytes < chunk.length && total_consumed == cstr.length |
| 78 | + end |
| 79 | + |
| 80 | + expect(result).to eq(str) |
| 81 | + expect(total_consumed).to eq(cstr.length) |
| 82 | + end |
| 83 | + end |
| 84 | + |
20 | 85 | describe 'streaming decompress + GC.compact' do
|
21 | 86 | it 'shoud work' do
|
22 | 87 | # str = SecureRandom.hex(150)
|
|
109 | 174 | end
|
110 | 175 | end
|
111 | 176 | end
|
112 |
| - |
|
0 commit comments