Class: Async::HTTP::Body::Readable

Inherits:
Object
  • Object
show all
Defined in:
lib/async/http/body/readable.rb

Overview

A generic base class for wrapping body instances. Typically you’d override ‘#read`.

Direct Known Subclasses

Buffered, Chunked, File, Fixed, Remainder, Wrapper, Writable

Instance Method Summary collapse

Instance Method Details

#close(error = nil) ⇒ Object

The consumer can call stop to signal that the stream output has terminated.



38
39
# File 'lib/async/http/body/readable.rb', line 38

def close(error = nil)
end

#eachObject

Enumerate all chunks until finished. Then invoke ‘#close`.



56
57
58
59
60
61
62
63
64
65
# File 'lib/async/http/body/readable.rb', line 56

def each
	return to_enum unless block_given?
	
	while chunk = self.read
		yield chunk
		# chunk.clear
	end
ensure
	self.close($!)
end

#empty?Boolean

Will read return any data?

Returns:

  • (Boolean)


42
43
44
# File 'lib/async/http/body/readable.rb', line 42

def empty?
	false
end

#finishObject

Read all remaining chunks into a buffered body and close the underlying input.



29
30
31
32
33
34
35
# File 'lib/async/http/body/readable.rb', line 29

def finish
	buffered = Buffered.for(self)
	
	self.close
	
	return buffered
end

#joinObject

Read all remaining chunks into a single binary string.



68
69
70
71
72
73
74
75
76
77
# File 'lib/async/http/body/readable.rb', line 68

def join
	buffer = IO::Buffer.new
	
	self.each do |chunk|
		buffer << chunk
		chunk.clear
	end
	
	return buffer
end

#lengthObject



46
47
48
# File 'lib/async/http/body/readable.rb', line 46

def length
	nil
end

#readObject

Read the next available chunk.



51
52
53
# File 'lib/async/http/body/readable.rb', line 51

def read
	nil
end