Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Add test and support for compressing and decompressing byte buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
iconara committed Jun 21, 2014
1 parent f3520b5 commit 9b0cb3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/cql/compression/lz4_compressor.rb
Expand Up @@ -30,11 +30,11 @@ def compress?(str)
end

def compress(str)
[str.bytesize, LZ4::Raw.compress(str).first].pack(BUFFER_FORMAT)
[str.bytesize, LZ4::Raw.compress(str.to_s).first].pack(BUFFER_FORMAT)
end

def decompress(str)
decompressed_size, compressed_data = str.unpack(BUFFER_FORMAT)
decompressed_size, compressed_data = str.to_s.unpack(BUFFER_FORMAT)
LZ4::Raw.decompress(compressed_data, decompressed_size).first
end

Expand Down
12 changes: 12 additions & 0 deletions spec/cql/compression/compression_common.rb
Expand Up @@ -36,12 +36,24 @@
compressed.bytesize.should be < input.bytesize
end

it 'compresses byte buffers' do
input = Cql::Protocol::CqlByteBuffer.new('hello' * 100)
compressed = compressor.compress(input)
compressed.should == compressor.compress(input.to_s)
end

it 'decompresses compressed strings' do
input = compressed_string
decompressed = compressor.decompress(input)
decompressed.should == 'hellohellohellohellohello'
end

it 'decompresses byte buffers' do
input = Cql::Protocol::CqlByteBuffer.new(compressed_string)
decompressed = compressor.decompress(input)
decompressed.should == 'hellohellohellohellohello'
end

it 'decompresses its own compressed output' do
input = 'Ķ' * 100
output = compressor.decompress(compressor.compress(input))
Expand Down

0 comments on commit 9b0cb3e

Please sign in to comment.