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, Fixed, Remainder, Wrapper, Writable

Instance Method Summary collapse

Instance Method Details

#closeObject

Buffer any remaining body.



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

def close
	Buffered.for(self)
end

#eachObject

Enumerate all chunks until finished. If an error is thrown, #stop will be invoked.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/async/http/body/readable.rb', line 48

def each
	return to_enum unless block_given?
	
	while chunk = self.read
		yield chunk
	end
rescue
	stop($!)
	
	raise
end

#empty?Boolean

Will read return any data?

Returns:

  • (Boolean)


34
35
36
# File 'lib/async/http/body/readable.rb', line 34

def empty?
	false
end

#joinObject

Read all remaining chunks into a single binary string.



61
62
63
64
65
66
67
68
69
# File 'lib/async/http/body/readable.rb', line 61

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

#readObject

Read the next available chunk.



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

def read
	nil
end

#stop(error) ⇒ Object

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



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

def stop(error)
end