Class: Gio::InputStream

Inherits:
Object
  • Object
show all
Defined in:
lib/gio2/input-stream.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.open(*arguments) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# 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

Instance Method Details

#read(size = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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

#read_all(size) ⇒ Object



53
54
55
56
57
58
# 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

#read_all_rawObject



52
# File 'lib/gio2/input-stream.rb', line 52

alias_method :read_all_raw, :read_all

#read_rawObject



32
# File 'lib/gio2/input-stream.rb', line 32

alias_method :read_raw, :read