Sha256: 441fbf84ca896e66854066cb481594cda7c67615036db1f2365aaf1d01117926

Contents?: true

Size: 889 Bytes

Versions: 7

Compression:

Stored size: 889 Bytes

Contents

class Puppeteer::ProtocolStreamReader
  def initialize(client:, handle:, path:)
    @client = client
    @handle = handle
    @path = path
  end

  def read
    StringIO.open do |out|
      if @path
        File.open(@path, 'wb') do |file|
          io_read do |data|
            out.write(data)
            file.write(data)
          end
        end
      else
        io_read { |data| out.write(data) }
      end
      io_close

      out.string
    end
  end

  private def io_read(&block)
    eof = false
    until eof
      response = @client.send_message('IO.read', handle: @handle)
      eof = response['eof']
      data =
        if response['base64Encoded']
          Base64.decode64(response['data'])
        else
          response['data']
        end
      block.call(data)
    end
  end


  private def io_close
    @client.send_message('IO.close', handle: @handle)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
puppeteer-ruby-0.34.0 lib/puppeteer/protocol_stream_reader.rb
puppeteer-ruby-0.33.0 lib/puppeteer/protocol_stream_reader.rb
puppeteer-ruby-0.32.4 lib/puppeteer/protocol_stream_reader.rb
puppeteer-ruby-0.32.3 lib/puppeteer/protocol_stream_reader.rb
puppeteer-ruby-0.32.2 lib/puppeteer/protocol_stream_reader.rb
puppeteer-ruby-0.32.1 lib/puppeteer/protocol_stream_reader.rb
puppeteer-ruby-0.32.0 lib/puppeteer/protocol_stream_reader.rb