Skip to content

Commit

Permalink
add .decompress method to Gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed May 2, 2024
1 parent 59a92c8 commit 497a830
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/datadog/ci/transport/gzip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def compress(input)
gzip_writer.close
sio.string
end

def decompress(input)
sio = StringIO.new(input)
gzip_reader = Zlib::GzipReader.new(sio)
gzip_reader.read
ensure
gzip_reader&.close
end
end
end
end
Expand Down
30 changes: 23 additions & 7 deletions spec/datadog/ci/transport/gzip_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require_relative "../../../../lib/datadog/ci/transport/gzip"

RSpec.describe Datadog::CI::Transport::Gzip do
subject { described_class.compress(input) }

describe ".compress" do
let(:input) do
<<-LOREM
let(:input) do
<<-LOREM
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et est eu dui dignissim tempus. Aliquam
scelerisque posuere odio id sollicitudin. Etiam dolor lorem, interdum sed mollis consectetur, sagittis a massa.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec gravida, libero ac gravida ornare, leo elit
Expand All @@ -18,8 +15,11 @@
commodo sapien vel, consequat felis. Aenean velit turpis, rhoncus in ipsum ut, tempor iaculis nisi. Fusce
faucibus consequat blandit. Nam maximus augue quis tellus cursus eleifend. Suspendisse auctor, orci sit amet
vehicula molestie, magna nibh rutrum metus, eget sagittis felis mauris eu quam. Vivamus ut vulputate est.
LOREM
end
LOREM
end

describe ".compress" do
subject { described_class.compress(input) }

it "compresses" do
expect(input.size).to be > subject.size
Expand All @@ -31,4 +31,20 @@
end
end
end

describe ".decompress" do
subject { described_class.decompress(compressed_input) }

let(:compressed_input) do
sio = StringIO.new
writer = Zlib::GzipWriter.new(sio)
writer << input
writer.close
sio.string
end

it "decompresses" do
expect(subject).to eq(input)
end
end
end

0 comments on commit 497a830

Please sign in to comment.