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

#closeObject

Read all remaining chunks into a buffered 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.



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

def each
  return to_enum unless block_given?
  
  while chunk = self.read
    yield chunk
    # chunk.clear
  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.



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

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

#lengthObject



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

def length
  nil
end

#readObject

Read the next available chunk.



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

def read
  nil
end

#stop(error) ⇒ Object

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



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

def stop(error)
end