class Baidubce::Http::BaseHttpClient::BufWriter

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/baidubce/http/base_http_client.rb, line 143
def initialize()
    @buffer = ""
    @producer = Fiber.new { yield self if block_given? }
    @producer.resume
end

Public Instance Methods

<<(chunk)
Alias for: write
close() click to toggle source
# File lib/baidubce/http/base_http_client.rb, line 193
def close
end
closed?() click to toggle source
# File lib/baidubce/http/base_http_client.rb, line 189
def closed?
    false
end
inspect() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/baidubce/http/base_http_client.rb, line 181
def write(chunk)
    @buffer << chunk.to_s
    Fiber.yield
    self
end
Also aliased as: <<