class IO

IO class method patches

IO instance method patches

Constants

EMPTY_HASH
LINEFEED

def putc(obj) end

LINEFEED_RE

Public Class Methods

binread(name, length = nil, offset = nil) click to toggle source
# File lib/polyphony/extensions/io.rb, line 9
def binread(name, length = nil, offset = nil)
  File.open(name, 'rb:ASCII-8BIT') do |f|
    f.seek(offset) if offset
    length ? f.read(length) : f.read
  end
end
Also aliased as: orig_binread
binwrite(name, string, offset = nil) click to toggle source
# File lib/polyphony/extensions/io.rb, line 17
def binwrite(name, string, offset = nil)
  File.open(name, 'wb:ASCII-8BIT') do |f|
    f.seek(offset) if offset
    f.write(string)
  end
end
Also aliased as: orig_binwrite
orig_binread(name, length = nil, offset = nil)
Alias for: binread
orig_binwrite(name, string, offset = nil)
Alias for: binwrite
orig_popen(cmd, mode = 'r')
Alias for: popen
orig_read(name, length = nil, offset = nil, opt = EMPTY_HASH)
# if sep.is_a?(Integer)
#   sep = $/
#   limit = sep
# end
# File.open(name, 'r') do |f|
#   f.each_line(sep, limit, getline_args, &block)
# end

end

Alias for: read
orig_write(name, string, offset = nil, opt = EMPTY_HASH)

alias_method :orig_readlines, :readlines def readlines(name, sep = $/, limit = nil, getline_args = EMPTY_HASH)

File.open(name, 'r') do |f|
  f.readlines(sep, limit, getline_args)
end

end

Alias for: write
popen(cmd, mode = 'r') { |o| ... } click to toggle source
# File lib/polyphony/extensions/io.rb, line 69
def popen(cmd, mode = 'r')
  return orig_popen(cmd, mode) unless block_given?

  Open3.popen2(cmd) { |_i, o, _t| yield o }
end
Also aliased as: orig_popen
read(name, length = nil, offset = nil, opt = EMPTY_HASH) click to toggle source
# File lib/polyphony/extensions/io.rb, line 42
def read(name, length = nil, offset = nil, opt = EMPTY_HASH)
  if length.is_a?(Hash)
    opt = length
    length = nil
  end
  File.open(name, opt[:mode] || 'r') do |f|
    f.seek(offset) if offset
    length ? f.read(length) : f.read
  end
end
Also aliased as: orig_read
write(name, string, offset = nil, opt = EMPTY_HASH) click to toggle source
# File lib/polyphony/extensions/io.rb, line 61
def write(name, string, offset = nil, opt = EMPTY_HASH)
  File.open(name, opt[:mode] || 'w') do |f|
    f.seek(offset) if offset
    f.write(string)
  end
end
Also aliased as: orig_write

Public Instance Methods

<<(str) click to toggle source
# File lib/polyphony/extensions/io.rb, line 143
def <<(str)
  Polyphony.backend_write(self, str)
  self
end
Also aliased as: orig_write_chevron
__parser_read_method__() click to toggle source
# File lib/polyphony/extensions/io.rb, line 79
def __parser_read_method__
  :backend_read
end
feed_loop(receiver, method = :call, &block) click to toggle source
# File lib/polyphony/extensions/io.rb, line 230
def feed_loop(receiver, method = :call, &block)
  Polyphony.backend_feed_loop(self, receiver, method, &block)
end
getbyte() click to toggle source
# File lib/polyphony/extensions/io.rb, line 98
def getbyte
  char = getc
  char ? char.getbyte(0) : nil
end
Also aliased as: orig_getbyte
getc() click to toggle source
# File lib/polyphony/extensions/io.rb, line 104
def getc
  return @read_buffer.slice!(0) if @read_buffer && !@read_buffer.empty?
  
  @read_buffer ||= +''
  Polyphony.backend_read(self, @read_buffer, 8192, false, -1)
  return @read_buffer.slice!(0) if !@read_buffer.empty?

  nil
end
Also aliased as: orig_getc
gets(sep = $/, _limit = nil, _chomp: nil) click to toggle source
# File lib/polyphony/extensions/io.rb, line 149
def gets(sep = $/, _limit = nil, _chomp: nil)
  if sep.is_a?(Integer)
    sep = $/
    _limit = sep
  end
  sep_size = sep.bytesize

  @read_buffer ||= +''

  while true
    idx = @read_buffer.index(sep)
    return @read_buffer.slice!(0, idx + sep_size) if idx

    result = readpartial(8192, @read_buffer, -1)
    return nil unless result
  end
rescue EOFError
  return nil
end
Also aliased as: orig_gets
orig_getbyte()

def each_codepoint end

Alias for: getbyte
orig_getc()
Alias for: getc
orig_gets(sep = $/, _limit = nil, _chomp: nil)
Alias for: gets
orig_puts(*args)
Alias for: puts
orig_read(len = nil, buf = nil, buf_pos = 0)
Alias for: read
orig_read_nonblock(maxlen, buf = nil, _options = nil)
Alias for: read_nonblock
orig_readpartial(len = nil, buf = nil, buf_pos = 0)
Alias for: read
orig_write(str, *args)
Alias for: write
orig_write_chevron(str)
Alias for: <<
orig_write_nonblock(string, _options = {})

def readlines(sep = $/, limit = nil, chomp: nil) end

Alias for: write_nonblock
puts(*args) click to toggle source
# File lib/polyphony/extensions/io.rb, line 182
def puts(*args)
  if args.empty?
    write LINEFEED
    return
  end

  idx = 0
  while idx < args.size
    arg = args[idx]
    args[idx] = arg = arg.to_s unless arg.is_a?(String)
    if arg =~ LINEFEED_RE
      idx += 1
    else
      args.insert(idx + 1, LINEFEED)
      idx += 2
    end
  end

  write(*args)
  nil
end
Also aliased as: orig_puts
read(len = nil, buf = nil, buf_pos = 0) click to toggle source
# File lib/polyphony/extensions/io.rb, line 115
def read(len = nil, buf = nil, buf_pos = 0)
  if buf
    return Polyphony.backend_read(self, buf, len, true, buf_pos)
  end
  
  @read_buffer ||= +''
  result = Polyphony.backend_read(self, @read_buffer, len, true, -1)
  return nil unless result

  already_read = @read_buffer
  @read_buffer = +''
  already_read
end
Also aliased as: orig_read, orig_readpartial
read_loop(maxlen = 8192, &block) click to toggle source
# File lib/polyphony/extensions/io.rb, line 226
def read_loop(maxlen = 8192, &block)
  Polyphony.backend_read_loop(self, maxlen, &block)
end
read_nonblock(maxlen, buf = nil, _options = nil) click to toggle source
# File lib/polyphony/extensions/io.rb, line 222
def read_nonblock(maxlen, buf = nil, _options = nil)
  buf ? readpartial(maxlen, buf) : readpartial(maxlen)
end
Also aliased as: orig_read_nonblock
readpartial(len, str = +'', buffer_pos = 0, raise_on_eof = true) click to toggle source
# File lib/polyphony/extensions/io.rb, line 130
def readpartial(len, str = +'', buffer_pos = 0, raise_on_eof = true)
  result = Polyphony.backend_read(self, str, len, false, buffer_pos)
  raise EOFError if !result && raise_on_eof

  result
end
splice(src, maxlen) click to toggle source
# File lib/polyphony/extensions/io.rb, line 258
def splice(src, maxlen)
  Polyphony.backend_splice(src, self, maxlen)
end
splice_to_eof(src, chunksize = 8192) click to toggle source
# File lib/polyphony/extensions/io.rb, line 262
def splice_to_eof(src, chunksize = 8192)
  Polyphony.backend_splice_to_eof(src, self, chunksize)
end
wait_readable(timeout = nil) click to toggle source
# File lib/polyphony/extensions/io.rb, line 234
def wait_readable(timeout = nil)
  if timeout
    move_on_after(timeout) do
      Polyphony.backend_wait_io(self, false)
      self
    end
  else
    Polyphony.backend_wait_io(self, false)
    self
  end
end
wait_writable(timeout = nil) click to toggle source
# File lib/polyphony/extensions/io.rb, line 246
def wait_writable(timeout = nil)
  if timeout
    move_on_after(timeout) do
      Polyphony.backend_wait_io(self, true)
      self
    end
  else
    Polyphony.backend_wait_io(self, true)
    self
  end
end
write(str, *args) click to toggle source
# File lib/polyphony/extensions/io.rb, line 138
def write(str, *args)
  Polyphony.backend_write(self, str, *args)
end
Also aliased as: orig_write
write_nonblock(string, _options = {}) click to toggle source
# File lib/polyphony/extensions/io.rb, line 217
def write_nonblock(string, _options = {})
  write(string)
end
Also aliased as: orig_write_nonblock