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.



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

def close(error = nil)
end

#eachObject

Enumerate all chunks until finished, then invoke ‘#close`.



53
54
55
56
57
58
59
60
# File 'lib/async/http/body/readable.rb', line 53

def each
  while chunk = self.read
    yield chunk
    # chunk.clear
  end
ensure
  self.close($!)
end

#empty?Boolean

Will read return any data?

Returns:

  • (Boolean)


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

def empty?
  false
end

#finishObject

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



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

def finish
  # Internally, this invokes `self.each` which then invokes `self.close`.
  Buffered.for(self)
end

#joinObject

Read all remaining chunks into a single binary string using ‘#each`.



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

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

#lengthObject



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

def length
  nil
end

#readObject

Read the next available chunk.



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

def read
  nil
end