Class: Baidubce::Http::BaseHttpClient::BufWriter
- Inherits:
-
Object
- Object
- Baidubce::Http::BaseHttpClient::BufWriter
- Defined in:
- lib/baidubce/http/base_http_client.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize ⇒ BufWriter
constructor
A new instance of BufWriter.
- #inspect ⇒ Object
- #read(bytes = nil, outbuf = nil) ⇒ Object
- #write(chunk) ⇒ Object (also: #<<)
Constructor Details
#initialize ⇒ BufWriter
Returns a new instance of BufWriter.
143 144 145 146 147 |
# File 'lib/baidubce/http/base_http_client.rb', line 143 def initialize() @buffer = "" @producer = Fiber.new { yield self if block_given? } @producer.resume end |
Instance Method Details
#close ⇒ Object
193 194 |
# File 'lib/baidubce/http/base_http_client.rb', line 193 def close end |
#closed? ⇒ Boolean
189 190 191 |
# File 'lib/baidubce/http/base_http_client.rb', line 189 def closed? false end |
#inspect ⇒ Object
196 197 198 |
# File 'lib/baidubce/http/base_http_client.rb', line 196 def inspect "@buffer: " + @buffer[0, 32].inspect + "...#{@buffer.size} bytes" end |
#read(bytes = nil, outbuf = nil) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/baidubce/http/base_http_client.rb', line 149 def read(bytes = nil, outbuf = nil) ret = "" while true if bytes fail if bytes < 0 piece = @buffer.slice!(0, bytes) if piece ret << piece bytes -= piece.size break if bytes == 0 end else ret << @buffer @buffer.clear end if @producer.alive? @producer.resume else break end end if outbuf outbuf.clear outbuf << ret end return nil if ret.empty? && !bytes.nil? && bytes > 0 ret end |
#write(chunk) ⇒ Object Also known as: <<
181 182 183 184 185 |
# File 'lib/baidubce/http/base_http_client.rb', line 181 def write(chunk) @buffer << chunk.to_s Fiber.yield self end |