Class: Puppeteer::Page::ProtocolStreamReader

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/page.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, handle:, path:) ⇒ ProtocolStreamReader

Returns a new instance of ProtocolStreamReader.



990
991
992
993
994
# File 'lib/puppeteer/page.rb', line 990

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

Instance Method Details

#readObject



996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/puppeteer/page.rb', line 996

def read
  out = StringIO.new
  File.open(@path, 'wb') do |file|
    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
      out.write(data)
      file.write(data)
    end
  end
  @client.send_message('IO.close', handle: @handle)
  out.read
end