Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

GLib::IOChannel

class GLib::IOChannel

GLib::IOChannel provides portable support for files, sockets and pipes.

Included Modules

  • Enumerable

Class Methods

GLib::IOChannel.open(filename, mode = "r") [ {|channel|...} ]
Creates a channel using a file. If block given, channel is closed automatically
  • filename: the file to open
  • mode: mode flags
  • Returns: the channel
GLib::IOChannel.open(fd) [ {|channel|...} ]
Opens a channel using an existing file descriptor. If block given, channel is closed automatically.
  • fd: the descriptor. (UNIX only)
  • Returns: the channel
GLib::IOChannel.new(filename, mode = "r")
Creates a channel with a file
  • filename: the file name
  • mode: the file creation flags
GLib::IOChannel.new(fd)
Associates an existing UNIX file descriptor with an IOChannel. (Unix only)
  • fd: the file descriptor
GLib::IOChannel.open
  • Returns: self: FIXME

Instance Methods

fileno
file descriptor of channel. (UNIX only)
to_i
Same as GLib::IOChannel#fileno
read(count = nil)
Reads count characters. If count is nil, reads to the end of file.
  • Returns: the string received, or "" if already at EOF
readchar
Reads a single char, or throws an exception if at end of file.
  • Returns: the char
getc
Reads a single char.
  • Returns: the char or nil if at EOF
readline(rs = nil)
Reads a line from the channel. throws an exception if at end of file.
  • rs: the record separator used for line breaks
  • Returns: the line
gets(rs = nil)
reads a line from the channel.
  • rs: the record separator used for line breaks
  • Returns: the line or nil if at end of file
each_line(rs = nil) {|line|...}
performs block operation on each line of the file.
  • rs: the record separator used to determine line breaks
  • Returns: self
each(rs=nil) {|line|...}
Same as GLib::IOChannel#each_line
each_char {|char|...}
Passes each char of the file to a block.
  • Returns: self
write(str)
Writes a string to the channel.
  • str: the string
  • Returns: self
printf(...)
Writes a printf style string.
print(...)
Prints any arguments given, or $_
puts(...)
Prints arguments given, or newline if none specified.
putc(ch)
Writes a char.
  • ch: the char
  • Returns: self
flush
Flushes output.
  • Returns: self
seek(offset, type = IOChannel::SEEK_SET)
Seeks into file.
pos=
sets the offset from the start of the file.
  • Returns: self
close
Closes the file.
create_watch(condition)
creates a GLib::Source which is dispatched when condition is met.
add_watch(condition) {|channel, condition|...}
Uses a GLib::Source to watch the IOChannel from the GTK main loop. The associated block should end with false to stop further watching, or true to continue.
buffer_size
The buffer size of the channel
buffer_size=
Sets the buffer size for the channel
buffer_condition
IO_IN set if buffer has data to be read. IO_OUT set if space available to write.
flags
The current IOChannel flags. A bitwise combination of flags. see GLib::IOChannel::FLAG_NONBLOCK
flags=
Sets the flags. For example, with GLib::IOChannel::FLAG_NONBLOCK
buffered
true if the channel is buffered
buffered=
Enables/disables buffering
encoding
The current encoding - default is 'UTF-8'
encoding=
Sets the character encoding. Set to '' for binary files
print
  • Returns: self: FIXME
printf
  • Returns: self: FIXME
puts
  • Returns: self: FIXME
set_buffer_size
  • Returns: self: FIXME
set_buffered
  • Returns: self: FIXME
set_encoding
  • Returns: self: FIXME
set_flags
  • Returns: self: FIXME
set_pos
  • Returns: self: FIXME

Constants

Seek constants

SEEK_CUR
Seek offset is relative to current position
SEEK_SET
Seek offset is relative to start
SEEK_END
Seek offset is relative to end

Status constants

These are used internally to raise exceptions.

STATUS_ERROR
IO error - raises a RuntimeError
STATUS_NORMAL
No error
STATUS_EOF
End of file - raises an EOFError
STATUS_AGAIN
Can perform operation again - raises a RuntimeError with "G_IO_STATUS_AGAIN"

Condition constants

IN
There is data to read
OUT
Data can be written without blocking
PRI
Priority data to be written
ERR
Errors
HUP
Hung up
NVAL
Invalid request (file descriptor not open)

IO Flag constants

Flag operations use a bitwise combination of these.

FLAG_APPEND
Append mode.
FLAG_NONBLOCK
Nonblocking mode.
FLAG_READABLE
Channel is readable. Flag cannot be changed.
FLAG_WRITEABLE
Channel is writeable. Flag cannot be changed.
FLAG_IS_SEEKABLE
Can seek in channel. Flag cannot be changed.
FLAG_MASK
Mask of all the flags
FLAG_GET_MASK
Same GLib::IOChannel::FLAG_MASK
FLAG_SET_MASK
Masks only the changeable bits.