File: inflate.rb

package info (click to toggle)
ruby-protocol-http 0.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 840 kB
  • sloc: ruby: 6,904; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.

require "protocol/http/body/buffered"
require "protocol/http/body/deflate"
require "protocol/http/body/inflate"

require "securerandom"

describe Protocol::HTTP::Body::Inflate do
	let(:sample) {"The quick brown fox jumps over the lazy dog."}
	let(:chunks) {[sample] * 1024}
	
	let(:body) {Protocol::HTTP::Body::Buffered.new(chunks)}
	let(:deflate_body) {Protocol::HTTP::Body::Deflate.for(body)}
	let(:compressed_chunks) {deflate_body.join.each_char.to_a}
	let(:compressed_body_chunks) {compressed_chunks}
	let(:compressed_body) {Protocol::HTTP::Body::Buffered.new(compressed_body_chunks)}
	let(:decompressed_body) {subject.for(compressed_body)}
	
	it "can decompress a body" do
		expect(decompressed_body.join).to be == chunks.join
	end
	
	with "incomplete input" do
		let(:compressed_body_chunks) {compressed_chunks.first(compressed_chunks.size/2)}
		
		it "raises error when input is incomplete" do
			expect{decompressed_body.join}.to raise_exception(Zlib::BufError)
		end
	end
end