class Gio::InputStream

Public Class Methods

open(*arguments) { |input_stream| ... } click to toggle source
# File lib/gio2/input-stream.rb, line 20
def open(*arguments)
  input_stream = new(*arguments)
  return input_stream unless block_given?

  begin
    yield(input_stream)
  ensure
    input_stream.close unless input_stream.closed?
  end
end

Public Instance Methods

read(size=nil) click to toggle source
# File lib/gio2/input-stream.rb, line 33
def read(size=nil)
  if size.nil?
    all = "".force_encoding("ASCII-8BIT")
    buffer_size = 8192
    buffer = " ".force_encoding("ASCII-8BIT") * buffer_size
    loop do
      read_bytes = read_all_raw_compatible(buffer)
      all << buffer.byteslice(0, read_bytes)
      break if read_bytes != buffer_size
    end
    all
  else
    buffer = " " * size
    read_bytes = read_raw_compatible(buffer)
    buffer.replace(buffer.byteslice(0, read_bytes))
    buffer
  end
end
Also aliased as: read_raw
read_all(size) click to toggle source
# File lib/gio2/input-stream.rb, line 53
def read_all(size)
  buffer = " " * size
  read_bytes = read_all_raw_compatible(buffer)
  buffer.replace(buffer.byteslice(0, read_bytes))
  buffer
end
Also aliased as: read_all_raw
read_all_raw(size)
Alias for: read_all
read_raw(size=nil)
Alias for: read

Private Instance Methods

read_all_raw_compatible(buffer) click to toggle source
# File lib/gio2/input-stream.rb, line 72
def read_all_raw_compatible(buffer)
  if (GLib::VERSION <=> [2, 62, 0]) >= 0
    _success, _buffer, read_bytes = read_all_raw(buffer)
    read_bytes
  elsif (GLib::VERSION <=> [2, 36, 0]) >= 0
    _success, read_bytes = read_all_raw(buffer)
    read_bytes
  else
    _success, read_bytes = read_all_raw(buffer, buffer.bytesize)
    read_bytes
  end
end
read_raw_compatible(buffer) click to toggle source
# File lib/gio2/input-stream.rb, line 61
def read_raw_compatible(buffer)
  if (GLib::VERSION <=> [2, 62, 0]) >= 0
    read_bytes, _buffer = read_raw(buffer)
    read_bytes
  elsif (GLib::VERSION <=> [2, 36, 0]) >= 0
    read_raw(buffer)
  else
    read_bytes = read_raw(buffer, buffer.bytesize)
  end
end