class IO

Augment the IO class to allow it to determine if an input object has data waiting and to add a binread instance method which will read external input as binary, then close the file.

Public Instance Methods

binread() click to toggle source

Read the entire contents of the IO stream in binary mode and close it.

# File buryspam.rb, line 136
def binread
  binmode
  data = read
  close
  data
end
has_input?() click to toggle source

Determine if there is input available in the IO stream. Uses both select and getc. Returns true if there is input waiting, false otherwise. Used to determine if $stdin has input waiting.

# File buryspam.rb, line 127
def has_input?
  if IO.select([self], nil, nil, 1).nil? || (byte = getbyte).nil?
    return false
  end
  ungetbyte(byte)
  true
end