Sha256: 5c8fa86ad414073eb2707d91845139a2468fc56523241304e7f806c6e1a13a06

Contents?: true

Size: 1006 Bytes

Versions: 26

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

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

require 'zlib'

require_relative 'deflate'

module Protocol
	module HTTP
		module Body
			class Inflate < ZStream
				def self.for(body, encoding = GZIP)
					self.new(body, Zlib::Inflate.new(encoding))
				end
				
				def stream?
					false
				end
				
				def read
					return if @stream.finished?
					
					# The stream might have been closed while waiting for the chunk to come in.
					while chunk = super
						@input_length += chunk.bytesize
						
						# It's possible this triggers the stream to finish.
						chunk = @stream.inflate(chunk)
						
						break unless chunk&.empty?
					end
					
					if chunk
						@output_length += chunk.bytesize
					elsif !@stream.closed?
						chunk = @stream.finish
						@output_length += chunk.bytesize
					end
					
					if chunk.empty? and @stream.finished?
						return nil
					end
					
					return chunk
				end
			end
		end
	end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
protocol-http-0.32.0 lib/protocol/http/body/inflate.rb
protocol-http-0.31.0 lib/protocol/http/body/inflate.rb
protocol-http-0.30.0 lib/protocol/http/body/inflate.rb
protocol-http-0.29.0 lib/protocol/http/body/inflate.rb
protocol-http-0.28.2 lib/protocol/http/body/inflate.rb
protocol-http-0.28.1 lib/protocol/http/body/inflate.rb
protocol-http-0.28.0 lib/protocol/http/body/inflate.rb
protocol-http-0.27.0 lib/protocol/http/body/inflate.rb
protocol-http-0.26.8 lib/protocol/http/body/inflate.rb
protocol-http-0.26.7 lib/protocol/http/body/inflate.rb
protocol-http-0.26.6 lib/protocol/http/body/inflate.rb
protocol-http-0.26.5 lib/protocol/http/body/inflate.rb
protocol-http-0.26.4 lib/protocol/http/body/inflate.rb
protocol-http-0.26.3 lib/protocol/http/body/inflate.rb
protocol-http-0.26.2 lib/protocol/http/body/inflate.rb
protocol-http-0.26.1 lib/protocol/http/body/inflate.rb
protocol-http-0.26.0 lib/protocol/http/body/inflate.rb
protocol-http-0.25.0 lib/protocol/http/body/inflate.rb
protocol-http-0.24.7 lib/protocol/http/body/inflate.rb
protocol-http-0.24.6 lib/protocol/http/body/inflate.rb